Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Help with this string
09-23-2013, 04:46 PM #1
- Join Date
- Sep 2013
- Thanked 0 Times in 0 Posts
Help with this string
I can't get this to work. It asks me for all the inputs then after the last input the webpage can't load.
adjective = prompt('Enter a adjective: ');
location = prompt('Enter a location: ');
firstName = prompt('Whats your name: ');
color = prompt('Whats your favorite color: ');
document.write('Last night I visited the ' + adjective + ' restaurant I have ever been to.');
document.write('\nIt was located right in the middle of an ' + location + ' just outside of town.');
document.write('\nThe name of the place, \"' + firstName + '\'s, \" was lit up with big ' + color + ' lights.');
09-23-2013, 05:47 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,508 Times in 2,486 Posts
location is a reserved word and may not be used as the name of a variable.
The HTML newline character is <br> not \n.
Note how to escape an apostrophe.
I expect you can see how this script does not attempt to ensure that the user entries make sense, or indeed require any entry at all. If so you have learned something important - input validation is often 80% of a practical script.
Please do not make any more posts asking us to do your homework for you. Pretending that other people's work is your own is normally regarded as cheating. Dishonest, in fact.
I suppose that what we are all waiting for is a picture of Kate with the baby coming out. - ITV Reporter
Last edited by Philip M; 09-23-2013 at 06:31 PM.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.