I am very new to JavaScript and trying my best so please be patient with me. I am using if else
statements to ask two questions.
- where you live;
- how many hours you are home.
Depending on the answer house
or apartment
, and how long less than 5 hours, he recommends a pet.
The issue that I am having is if I type house and > 5 hours it also returns the choice for apartment for the > 5 hours.
Here's my code:
var residence = prompt("Enter House, Apartment or Dorm");
var hours = prompt("Amount of hours home", "");
if ((residence == "House" || "house") && (hours <= 5)) {
var x=window.confirm("You should get a hamster" + "\nWould you like to Purchase one?")
if (x)
window.alert("Thank you for your purchase!")
else
window.alert("Too bad")
}
else if ((residence == "House" || "house") && (hours > 5) && (hours <= 10)) {
var x = window.confirm("You should get a cat" + "\nWould you like to Purchase one?")
if (x)
window.alert("Thank you for your purchase!")
else
window.alert("Too bad")
}
if ((residence == "Apartment" || "apartment") && (hours <= 5)) {
var x = window.confirm("You should get a gold fish" + "\nWould you like to Purchase one?")
if (x)
window.alert("Thank you for your purchase!")
else
window.alert("Too bad")
}
I hope this makes sense for what I am asking. Thank you for your help.