0
Can anyone help me with this code in Java Script
JS The if else statement Entrance to the club is only permitted in pairs. Take the number of customers in the club as input, and, if all of them have a pair, output to the console "Right", otherwise output "Wrong". Sample Input 14 Sample Output Right function main() { var numberGuests = parseInt(readLine(), 10) // Your code here if (numberGuests % 2) == 0) { console.log("Right") } else { console.log("Wrong") } main() }
9 Réponses
+ 4
It's not necessary to call main() in Js practices since it's done by the compiler itself.
+ 3
Open parenthesis is missing in if
It should be
if((numberGuests % 2) == 0){
....
}
And you can also do this with a single pair of parenthesis
if (numberGuests % 2 == 0){
.....
}
+ 2
You need to use logical operators to combine two or more conditions
else if (score >= 40 && score <= 87){
console.log("good")
}
+ 2
(score = 40 - 87), it will set the score to -47, and if the score is not greater than 88, then this condition ,(score = 40 - 87), will be always true.
+ 1
Thanks so much eveyone that fixed my code !!
I have another question about a different challege, I have written a code for exam results and its working for "excellent" and "good" but its not working on the "fail" test case. It outputs "good" for a score of 18 for some reason:
else if
Тhe result of an exam will be determined as follows։
If the score is
88 and above => excellent
40-87 => good
0-39 => fail
You are given a program that takes the score as input.
Task
Complete the code to output the corresponding result (excellent, good, fail) to the console.
Sample Input
78
Sample Output
good
var score = parseInt(readLine(), 10)
/*
88 and above => excellent
40-87 => good
0-39 => fail
*/
// your code goes here
if (score >= 88) {
console.log("excellent")
}
else if (score = 40-87) {
console.log("good")
}
else {
console.log("fail")
}
+ 1
Thank you Simba && Rupali ;-)
0
Sean Taylor you're welcome 8D
0
In your code, you have an unmatched bracket :
function main() {
var numberGuests = parseInt(readLine(), 10)
// Your code here
if(numberGuests % 2 == 0) {
console.log("Right")
} else {
console.log("Wrong")
}
}
0
One liner ? :
const main = () => console.log(+readLine() % 2 === 0 ? "Right" : "Wrong")