Why this code doesn't work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
8th Apr 2021, 9:27 AM
Тимур Завьялов
Тимур Завьялов - avatar
12 Answers
+ 5
console.log( [ "Even", "Odd" ] [ a % 2 ] ); It's an array with conditional index. The `a % 2` expression evaluates to 0 when <a> is an even number, and 1 when <a> is odd number. The evaluation result of `a % 2` is used to decide which element is chosen from the array, to be printed into the console.
8th Apr 2021, 9:39 AM
Ipang
+ 6
Good stuff. [ a % 2] returns 0 or 1, and that takes "Even" or "Odd". ...talking to myself :)
9th Apr 2021, 11:50 AM
Bladimir Jiménez
Bladimir Jiménez - avatar
+ 4
Sample Output: "0 is even" "1 is odd" "2 is even"
9th Apr 2021, 5:21 PM
Juan Angel Luzardo Muslera
Juan Angel Luzardo Muslera - avatar
+ 4
Vasiliy You are an excellent programmer, I like your excellence and the cleanliness of your codes. Input: "2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50 etc" Output: even Input: "1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49 etc" Output: odd 𝙶𝚛𝚎𝚎𝚝𝚒𝚗𝚐𝚜 𝚍𝚎𝚊𝚛 𝚏𝚛𝚒𝚎𝚗𝚍ヅ
10th Apr 2021, 5:46 PM
Juan Angel Luzardo Muslera
Juan Angel Luzardo Muslera - avatar
+ 2
Odd + Odd = Even Odd + Even = Odd Even + Even = Even Odd × Odd = Odd Odd × Even = Even Even × Even = Even
27th Jan 2024, 12:57 PM
Juan Angel Luzardo Muslera
Juan Angel Luzardo Muslera - avatar
+ 1
Ipang, thank you)
8th Apr 2021, 9:42 AM
Тимур Завьялов
Тимур Завьялов - avatar
+ 1
No problem bro because alert in js code alert<delete>then type console.log
9th Apr 2021, 11:02 AM
Dark developer {<[Čõđę Ŵåř]>}🇪🇹
Dark developer {<[Čõđę Ŵåř]>}🇪🇹 - avatar
+ 1
Juan Angel Luzardo Muslera Another example of the output ☺️ Input: " " Output: even
10th Apr 2021, 1:20 PM
Solo
Solo - avatar
0
No problem bro 👌
8th Apr 2021, 9:49 AM
Ipang
0
console.log instead of alert
9th Apr 2021, 1:24 PM
Sunil Kumar Choudari
Sunil Kumar Choudari - avatar
0
Juan Angel Luzardo Muslera Thank you very much for your rating, but I still know too little to consider myself a programmer ☺️
10th Apr 2021, 6:42 PM
Solo
Solo - avatar
0
hello.. everybody I want to known which books can help me to learn on how to create a virtual private Network (VPN)
26th May 2022, 7:42 PM
P_vanny
P_vanny - avatar