+ 1

My code below is supposed to take a number as input and output the color name at that index. Please explain where I went wrong.

https://code.sololearn.com/ckf66M7SCB8i/?ref=app My code only prints Red[1] 1 no matter what number you input.

8th Apr 2023, 9:01 PM
Kody Marsh
Kody Marsh - avatar
3 odpowiedzi
+ 4
kody marsh Equality operator: "==". But it would be better that way: if(0<x & x<=10){ cat(colors[x]) }else{ cat("Please input a number between 1-10") } P. S: "If you want to address someone personally, then click @ and a list of users will open."
8th Apr 2023, 9:29 PM
Solo
Solo - avatar
+ 6
Use == instead of <- in if-else statements
8th Apr 2023, 11:48 PM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 2
Thank you Solo and Hasnain [ACTIVE CHALLENGER] for the help!
9th Apr 2023, 5:21 AM
Kody Marsh
Kody Marsh - avatar