Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm having the strangest problem right now; This if-statement below should run the console.log("It's night!") when the currentHour is between 22 and 07, but for some reason it doesn't!
console.log("hello");
console.log(currentHour);
if (currentHour >= 22 && currentHour <= 7) {console.log("Its night!");};
Console output:
hello 22
So the if-statement is not run.
If current hour is HIGHER/equal than 22 AND LOWER/equal than seven will never be true.
What you probably want:
if(currentHour >= 22 || currentHour <=7)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
confirm("Ready to play???!!!");
var age = prompt("How old are you?");
console.log(age);
if (age >= 21) {
console.log("you can go in and have drinks :)");
}
if (age >= 19) {
console.log("go in but you cant drink");
} else if (age < 19) {
console.log("sorry cant let you in!");
}
When I typed in 23, it will both log the first one (age >= 21) and the second one (age >= 19).
I want it only show the first one, how could I do that?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I'm trying to define the parameter firstname from the prompt but it shows that it's undefined and goes at the end of the template string.
'use strict';
const yearsret = (year, firstname) => {
const age = 2022 - year;
const retir = 60 - age;
return `${firstname} retires in ${retir} years`;
}
console.log(yearsret(prompt('Please enter your birth year')), (prompt('Please enter your Name')));
and the result
undefined retires in 27 years Ali
This is a typo. Your parenthesis () is in the incorrect spot. Try this:
console.log(yearsret(prompt('Please enter your birth year'), (prompt('Please enter your Name'))));
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my code but when i run this code in console always giving me Congratulations.
Help me for solve this problem.
var val=Math.floor(Math.random() * 10) + 1;
console.log(val);
var Predict = Number(prompt("Prediction ?"));
for(var i=1 ; i <= 3; i++){
if(Predict<val){console.log("Up")};
if(Predict=val){console.log("Congratulations") };
if(Predict>val){console.log("Down")}
}
Equal operator assigns the right hand to the left hand and so the result is always true! To compare two values use double equals like this:
if (Predict==val){console.log("Congratulations") };
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
We added two values using Math.ceil.
One became 50 when I used Math.ceil, and the other became 80 when I used Math.ceil.
For some reason, when I add 50 and 80, the result is 131.
console.log(Math.ceil(e.currentTarget.clientHeight) // 50
console.log(Math.ceil(e.currentTarget.scrollTop)) // 80
console.log(Math.ceil(e.currentTarget.clientHeight) + Math.ceil(e.currentTarget.scrollTop)); // 131
status of implementation
e.currentTarget.clientHeight // 50
e.currentTarget.scrollTop // 80.1111145019531
Math.ceil(80.1111145019531) = 81
Thus the sum is 131. Math.ceil always rounds up.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I've been trying to figure out what is wrong with my code. In the console I keep on getting "expected expression, got '||'" but I've got no idea why. Can anyone enlighten me?
Thanks
if (isNaN(value)) || value < 0 || value > 9 {
result.innerHTML = `<p class="result">${text[0]}</p>`;
}
You have misplaced parentheses on your if statement.
Replace this:
if (isNaN(value)) || value < 0 || value > 9
With this:
if (isNaN(value) || value < 0 || value > 9)