vendredi 5 janvier 2018

How do I compare the prompt response to my variable?

The user is supposed to enter one of several given names into the prompt box. If their response is not one of the given names, they are told that that is not a valid response. If they do, however, then they are told who they have selected. The issue is, no matter what I type in, it keeps saying that it's an invalid name. Any Advice how to fix this?

 <html>
<body bgcolor = "firebrick">
    <title>Dinner Plans</title>
    <center><h1><b> Dinner Plans</h1>
        <p> Guests to Pick From:</p></b>
        <p> Jane, Lisa, Taylor, Chris, Alyssa, Will and Jessica </p>
       <button onclick="Invites()">Click To Invite</button>
  <div id = "Coming"></div>
<script>
function Invites() {
var txt;
var person = prompt("Who is Coming For Dinner?", "Enter Names Here");
if (person == null || person != guest) {
    txt = "Not A Valid Guest.";
} 
else {
    txt = "Your Invited Guests Are:" + person;
}
document.getElementById("Coming").innerHTML = txt;
}

function guest ( slices , toppings ) {
  this.numSlices = slices;
  this.numToppings = toppings; 
}
var Jane = new guest( 2, "Mushroom", "Onions", "Peppers", "Olives");
var Lisa = new guest(3, "Pepperoni", "Ham", "Pineapple");
var Taylor = new guest(3, "Extra Cheese", "Pepperoni", "Sausage", "Bacon");
var Chris = new guest(2, "Mushroom", "Sausage", "Bacon", "Ham", "Onion", "Peppers");
var Alyssa = new guest(1, " Pepperoni", "Bacon");
var Will = new guest(2, "Extra Cheese", "Sausage", "Bacon", "Onion", "Peppers", "Olives");
var Jessica = new guest(2, "Pepperoni", "Bacon", "Ham", "Pineapple", "Onion", "Peppers");

if (Invites == null || Invites == "") {
    txt = " You invited zero guests, you have a pizza all to yourself!";
} else { 
    txt = " You Invited:" + Invites; 
}

        </script>

Aucun commentaire:

Enregistrer un commentaire