Reputation: 85
I am doing some very basic code within JavaScipt. I am going through If statements. whenever I enter a number over 100 (either for c or d) I don't get an alert that "You number is over one hundred". What is it that I am missing??? Feel like it's a simple solution I'm just not seeing it.
var c = prompt("Please enter a number between 1 and 100");
var d = prompt("Please enter a number between 1 and 100");
if (c || d <=100) {
if (c == d) {
alert("Your first number is equal to your second number!")
}else{
alert("Your first number is not equal to your second number!")
}
}else{
alert("Your number is over 100")
};
Upvotes: 0
Views: 72
Reputation: 17880
Change if (c || d <=100)
to if (c <= 100 && d <= 100)
since you want to ensure both the input numbers are less than 100.
Upvotes: 0
Reputation: 2169
You can read the if statement more accurately like this:
if(c || (d < = 100)){
Because c will always be true unless you enter 0, it will never say "your number is over 100"
You can rewrite it to something like this if you want to check if either are over 100:
if(c <= 100 || d <= 100){
Upvotes: 2