JavaScript Question 11 Functions Recap (answer shows correct but no log)


The questions is

Write a function called nameString()
It should take name as a parameter.
The function returns a string equal to "Hi, I am" + " " + name.
Call nameString() by passing it your name, and use console.log to print the output.

My code is

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

The program is saying I got the problem correct but the log screen is showing a blank page instead of "hi, i am roy"
Is there a glitch or an error on my end?


What is name here? You can't reference a function parameter outside of the function.

Is newName what you wanted to log to the console?


Should fix it :slightly_smiling:


yea that fixed it! thanks!


Could this exercise perhaps be modified/fixed? As its solution varies from the given instructions. When I follow the instructions and type the console.log outside the function it gives me "Thumbs up" and "Way to go!". But in reality the code does not print anything leaving the control window blank. But when I remove the console.log completely or move it inside the function, it prints out "Hi, I am blahBlah", as told by exercise. So the system is happy with the code, but the bottom scorer is yelling "Oops! Try again.".
So the question is whom do we want to satisfy here? The bottom scorer, that tells you "well done" when the code is wrong or the control window that prints out what is requested, whilst no green light is given.


I have:

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

and it does both, print to the console and pass the lesson.


Ooh. So there is more than one way to satisfy both. Nice one!