Started writing some modified quiz questions to improve my skill, having a spot of bother with this one. | SoloLearn: Learn to code for FREE!

0

Started writing some modified quiz questions to improve my skill, having a spot of bother with this one.

This is a slightly modified question from one of the javascript quizzes, I don't want to be giving the answers away. what will the function ('help') return? function func(str){ var len = str.length; for(var i = 0; i < (len/2);i++) { if (str[i] !== str[len -1 -i]) return true; } return false; I've written it on some paper and tried to follow the loop through, when I was still having trouble I copied it to JS editor. I didn't get any return when I put it into the JS editor, I tried changing the function to func(str = 'help') and also added a 'document.write' after the 'var len = str.length;' but still haven't recieved anything in my console to help me run through this loop. Thanks in advance.

6/10/2020 3:11:45 PM

Michael Smyth

2 Answers

New Answer

+1

This should give you output: function func(str){ var len = str.length; for(var i = 0; i < (len/2);i++) { if (str[i] !== str[len -1 -i]) return true; } return false; } console.log(func("help")); On your question, you missed the closing curly bracket on your func definition.

0

Fantastic, got it all sorted now.