0
Beginner Javascript Problem
Trying to store variables from three prompts, and give an alert with the output from the prompts. I keep getting an error that ")" is missing from line 8, but I cannot figure it out. //Can anyone tell me what is wrong with this? var user = prompt("Please enter your name"); var age = prompt("Please enter your age"); var gender = prompt('Please enter your gender\n male or female'); if (gender == "female") { alert('Hi'+ user ' are a '+age' old woman'); } else { alert('Hi'+ user ' are a '+age' old man'); }
5 Respuestas
+ 4
Stephen Keen It should write like this.
alert('Hi' + user + ' are a ' + age + ' old man');
Here user and age is a variable so you should write without quote and when you add two or more than two string you should write +
+ 2
Stephen Keen Problem is in alert. You have Missed + after user in alert.
+ 1
try this
alert('Hi' + user + 'are a' + age + ' old woman');
alert('Hi' + user + 'are a' + age + ' old man');
or
alert(`Hi ${user} are a ${age} old ${gender}`);
alert(`Hi ${user} are a ${age} old ${gender}`);
+ 1
Thank you so much!
0
Hello Stephen Keen, the first error you had was that you were missing a + sign after the user variable. Remember that to concatenate it is like this:
"text" + variable + "text" + variable + ...
The other error I noticed is that when I put FeMaLe (uppercase) it went for the else statement. Which I solved with:
gender = gender.toLowerCase();
To convert to lowercase and if compare as it should be. I leave the code fixed, I hope it works for you.
https://code.sololearn.com/WP44N19d0mdg/?ref=app