Please help me about '9. What is programming?'


Above all, please excuse my poor English. I'm not living in English-speaking-country so my English writing is very insufficient.


prompt("What is your name?");
prompt("What is Ubuntu?");

I responded with two questions, ''What is your name?' and "What is Ubuntu?" just as "undefined".
But income is only one string, "undefined".
Is it correct to be printed out two "undifined" strings?
Please explain me about how the 'prompt' function works and what should I do to print out two strings in above situation.


prompt just asks for user input, you can use console.log to log the result of the prompts to the console:

console.log(prompt("What is your name?"));
console.log(prompt("What is Ubuntu?"));



The nature of Javascript means that when returning a call from a [prompt] function it will return the last line of code..

So in this case, whilst you've written out two prompt() calls it is the value assigned to the 2nd/last one that would be returned to the console..

This is because the return function within the prompt function (which is inbuilt into JS) only returns the last value..

If you wanted to print two values from the same two prompt() calls you could console.log() them..

console.log(prompt("What is your name?"));
console.log(prompt("What is Ubuntu?"));

Hope that helps and has cleared it up for you..

Alterntively some smarter people than I have explained prompt() and return() a bit better :smiley:


Thank you!! Actually I tried your adivice. But I had mistake to put semicolon into bracket like "console.log(prompt("What is your name?") ; )"


you do have to nest it right, otherwise it won't work. Good you got it to work, and it is also worth it to read @jimmynames explanation :slight_smile: