Returning array in Javascript function after splitting string -
very new javascript , not understanding why tutorial isn't accepting code answer...
challenge create function returns array after breaking string separate words.
here's have far:
function cutname(namestr) {   var newarray = namestr.split(' ');   return newarray(); }   this seems work when called, example returning following when given string "hello work" argument:
[ 'hello', 'does', 'this', 'work' ]   what heck doing wrong here? shouldn't above code suffice answer?
you need remove parenthesis return newarray;. when learning javascript, might want tools jsbin, give lot of helpful feedback , realtime results.
javascript
function cutname(namestr) {   var newarray = namestr.split(' ');   return newarray; }  var arr = cutname('hello work'); console.log(array.isarray(arr)); console.log(arr);   console output
true ["hello", "does", "this", "work"]        
Comments
Post a Comment