I have the following script:
function getMoods(nb) {
var index;
var a = [\"Banana\", \"Coconut\", \"Peach\", \"Apple\", ...];
for (index=0; index<
There are two problems:
A wrong use of the spread operator ...:
["Banana", "Coconut", "Peach", "Apple", ...];
This throws SyntaxError: expected expression, got ']'
, because after the spread operator there isn't any iterable object.
JavaScript doesn't support multiline strings.
You can use some alternatives:
Concatenate multiple strings
moods +=
'<div class="checkbox">'
+'<label for="'+a[index]+'">'
+'<input type="checkbox" id="'+a[index]+'" class="moods"> '+a[index]
+'</label>'
+'</div>';
Use \
at the end of each line to continue the string at the next one
moods += '\
<div class="checkbox">\
<label for="'+a[index]+'">\
<input type="checkbox" id="'+a[index]+'" class="moods"> '+a[index]+'\
</label>\
</div>';
Join an array of strings:
moods += [
'<div class="checkbox">',
'<label for="'+a[index]+'">',
'<input type="checkbox" id="'+a[index]+'" class="moods"> '+a[index],
'</label>',
'</div>'].join('');