Prompt section of chapter 7

Get help with Code for Teens
Katy
Posts: 5
Joined: Mon May 28, 2018 4:22 pm

Prompt section of chapter 7

Post by Katy » Fri Jan 18, 2019 8:27 pm

I am working on the prompt section of chapter 7 and when I typed the example code in instead of saying "Hello, Katy! You are 14 years old." The only thing it said was: "You are 14 years old." This does not make sense to me. (I tried typing it in some other ways and found when I put the code on one line and removed the semicolon in between the console ran the whole thing.)

prompt('What is your name?');
'Hello, ' + prompt('What is your name?') + '!';
'You are ' + prompt('How old are you?') + ' years old.';
"You are 14 years old."

(This is the code I saw in the book)


prompt('What is your name?');
'Hello, ' + prompt('What is your name?') + '! You are ' + prompt('How old are you?') + ' years old.';
"Hello, Katy! You are 14 years old."

(This is the code after I played with it a bit)

ᕙ(ළ෴ළ)ᕗ
Posts: 1
Joined: Mon Sep 17, 2018 7:07 pm

Re: Prompt section of chapter 7

Post by ᕙ(ළ෴ළ)ᕗ » Wed Feb 06, 2019 8:05 pm

You need to make the prompt a variable. Example: let promptVariable = prompt("What is your name?") and then do "hello" + promptVariable + "!".

Post Reply