Skip to content

Instantly share code, notes, and snippets.

@petrov82
Created February 20, 2014 22:03
Show Gist options
  • Select an option

  • Save petrov82/9124212 to your computer and use it in GitHub Desktop.

Select an option

Save petrov82/9124212 to your computer and use it in GitHub Desktop.
undefined error in my prompt
<!DOCTYPE html>
<html>
<head>
<title>User Interaction for JS</title>
</head>
<body>
<p>
<script>
// alert("You're Awesome!");
// todo: Ask the user for their name.
// Keep asking if an empty input is provided.
confirm('Are you having a good day?');
do {
var name = prompt('What is your name?');
} while (prompt() == false);
// todo: Show an alert message that welcomes the user based on their input.
if (prompt() == name) {
alert('Welcome to the site, ' + name);
} else {
confirm('Do you want to continue?')
}
// todo: Ask the user if they like pizza.
// Based on their answer tell show a creative alert message.
</script>
</body>
</html>
@WritingPanda
Copy link

// todo: Ask the user for their name.
//       Keep asking if an empty input is provided.
confirm('Are you having a good day?');

do {
    var name = prompt('What is your name?');
} while (name === undefined);

// todo: Show an alert message that welcomes the user based on their input.
if  (name) {
    alert('Welcome to the site, ' + name);
} else {
    confirm('Do you want to continue?')
}


// todo: Ask the user if they like pizza.
//       Based on their answer tell show a creative alert message.

@WritingPanda
Copy link

Now, I am not sure if this is working the way I think it is, but it works in the browser. We should walkthrough the logic to make sure everything is sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment