What´s wrong with my code?
jcteixeira
15 May 2018, 20:59function times2(blobst){
var newArray = [];
for(i = 0; i <blobst.length; i++){
newArray.push(blobst[i] * 2);
}
return newArray;
}
set('test', times2([1,2,3,4,5]))
{test}
why it doesn't work?
K.V.
17 May 2018, 01:07Hello.
Is that in a section or a passage? Is it indented?
Can you post more of the code?
jcteixeira
17 May 2018, 22:37Hi,
and thank you for the interest.
Yes, it's inside a section and indented (all java activated, function is blue, blobst yellow, etc).
It works fine out of Squiffy, showing the result: "2,4,6,8,10".
Richard Headkid
18 May 2018, 00:35This works for me:
Try this out: [[test section]]
[[test section]]:
function times2(blobst){
var newArray = [];
for(i = 0; i <blobst.length; i++){
newArray.push(blobst[i] * 2);
}
return newArray;
};
set('test', times2([1,2,3,4,5]));
{test}
OUTPUT
Try this out: test section
2,4,6,8,10
Richard Headkid
18 May 2018, 00:38PS
If I were you, I'd put that function in a master section. Then, You can call the function any time in the code:
Try this out: [[test section]]
[[test section]]:
set('test', times2([1,2,3,4,5]));
{test}
[[]]:
times2 = function(blobst){
var newArray = [];
for(i = 0; i <blobst.length; i++){
newArray.push(blobst[i] * 2);
}
return newArray;
};
jcteixeira
18 May 2018, 15:04Thank you, it works!
(declaring "i "):
[[test section]]:
var i;
function times2(blobst){
var newArray = [];
for(i = 0; i <blobst.length; i++){
newArray.push(blobst[i] * 2);
}
return newArray;
};
set('test', times2([1,2,3,4,5]));
{test}