Ask your own question, for FREE!
Computer Science 23 Online
OpenStudy (neonumbrella5115):

Could someone help me with a codeacademy program? (Java, beginner level)

OpenStudy (neonumbrella5115):

I keep receiving an error message: "SyntaxError: 'return' statement outside of function" For the following code: var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if(computerChoice<0.33) { return "rock"; } else if(0.34<computerChoice>0.66) { return "paper"; } else { return "scissors"; };

OpenStudy (karim728):

u sure this is java?

OpenStudy (neonumbrella5115):

Yeah. I'm in the Java beginner course.

OpenStudy (karim728):

what is the name of ut function?

OpenStudy (neonumbrella5115):

I don't have a function. Just two variable and an if/else is/else statement. Do I need a function?

OpenStudy (karim728):

wait ill run it myself and test it

OpenStudy (neonumbrella5115):

So after some fiddling around, codeacademy wanted the variable computerChoice to change to rock paper or scisssors, not to just return the value like I coded. :( Oh well. Thanks for trying to help me!!! I really appreciate it! :)

OpenStudy (karim728):

np

OpenStudy (karim728):

just curious tho.. why are you var in java? because java uses primitive data types

OpenStudy (karim728):

using var

OpenStudy (neonumbrella5115):

I'm not really the coding expert, I just follow how the website tells me to identify functions and variables with "var". Can I ask what "primitive data types" are?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!