Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+20 votes

Are we allowed to utilize a random method that randomly choose from 4 predetermined result ? Like left, right, up, down ?

asked in CSC211_Winter2018 by (1 point)

1 Answer

+11 votes

If you are asking if this is possible, then the answer is yes. One option is to use an array which is something we have not yet been taught but would be somewhat easy to learn.

Another way to do it that we do know would be to generate a random number of 1-4 and then assign if/else statements for each value and a certain result.

For example:

if (randomNumber == 1) {
   result = "left";

followed by if statements for 2-4 assigning a direction to each.

answered by (1 point)