javascript problem

var nameString = function (name) {
return "Hi, I am" + " " + name ;
};

console.log(nameString(chiman););

有咩問題呀??  我卡住左係codeacademy

本帖最後由 Jackass_TMxCK 於 2015-2-24 13:38 編輯

Inside parenthesis"()", you cannot put a semicolon inside.


console.log(myFn()); but not console.log(myFn(););

semicolon is to let interpreter or compiler know this is the end of line.


Another bug is string parameter should be wrapped with double or single quote: myFn('a string')

Boolean, variable, number etc. except string can be passed with no quoting. chiman should be wrapped or it is treated as variable.
Since variable chiman is not initialised, JavaScript cannot further process it.

This is the correct answer:
var nameString = function (name) {
return "Hi, I am" + " " + name ;
};

console.log(nameString("chiman"));


Good luck and happy coding newbie.

TOP

btw, return "Hi, I am "+ name; is slightly better

TOP

回覆 2# Jackass_TMxCK

THANK!!!!

TOP