r/CodingHelp • u/yeetrandom234 • Apr 25 '19
How would I do this? Trying to start coding in JavaScript by understanding pseudocode.
1
u/SupremeRedditBot Professional Bot || Mod Apr 25 '19
Please Add A Flair To Your Post!
Suggested Flair: [Javascript]
To add a flair:
Click
flairunderneath your postSelect a flair
Click
save
I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated ^response
1
Apr 25 '19
Modulo, sometimes called the remainder operator, will return the remainder of the division (assuming both numbers are positive). So for the pseudocode, the result of the conditional in the if statement will return false (5 mod 2 = 1....1 != 0). This means that the statement following the if statement will not run and the return 2 statement will run. The 2 will then be displayed when control returns to the original procedure call.
Edit: spelling
1
u/PC__LOAD__LETTER Apr 25 '19
Is the “mod” part the only bit that’s confusing? If so, others have explained it. If not, let me know and I can give it another explanation.
1
u/Shubham_Garg123 Apr 25 '19
I don't know java at all, I am currently learning C++ but seeing the code, I feel that output should be 2 which is the last option. Sorry if my answer is wrong (I don't think it can be wrong but I am just 16 yrs old so can't guarantee the answer)
1
4
u/chubbard022 Apr 25 '19
Think of mod as remainder, so if you could take 2 mod x where x is equal to five. You will get that 2 can go into 5 with a remainder of 1. So that’s what your answer would be