lundi 26 octobre 2020

How to fix an if loop to print odd/even number in R?

Im new to R. I got a code and need to find the two errors in it and fix them. Here is the original code

 x <- 34
if(x %% 3){print("This is an odd number)}else{
print("This is an even number")}

I figured out that the first error was a missing quotation mark after the odd number part. But I'm unsure of the second error. I did find out that the output for this code is "This is an odd number" but if you switch where odd and even are, the output is then "This is an even number". Im not really sure what to do.

Aucun commentaire:

Enregistrer un commentaire