+ 1
Even Odd Program
Is it possible to write a program in javascript which can take the number as input and output whether it's even or odd But wait you can't use any type of conditional statement (no if else, no switch case). Yes or No... If yes write it down below..... No chatGpt or any AI assistance.
6 Respuestas
+ 3
0 and 1 can also be used as index of a list or array. so we are not using switch case or if-else...
n & 1 works like n%2
console.log(['even', 'odd'][prompt() & 1])
+ 2
I will insert it.
https://sololearn.com/compiler-playground/WdnR27nrMZh1/?ref=app
you can't do that without selection.
but you can do that without the % operator.
+ 1
Arash Amorzesh the OP said not to use any type of conditional statement, you used a tenerary operator which is probably against the rules.
+ 1
Mustafa Raza
Modified Bob_Li's code a little bit.
console.log(['even','odd'][prompt()%2]);
+ 1
Zvi Thanks.
0
Gulshan Mahawar actually I think Bob_li’s solution is way cooler. I had to ask chatGTP to explain it and I still only get the basic idea!