java help (codecademy tut)...

Posts 1–13 of 13 · Page 1 of 1
java help (codecademy tut)...
so im learning java on codecademy and im on Compare Function part 2. what if choice 1 is rock... (i already ask for help but no one reply for shit...)

info given:
Code:
You're doing great! Now we consider the other scenarios. Let's break the problem down a little. What if choice1 is "rock"? Given choice1 is "rock",

a. if choice2 is "scissors", then "rock" wins.
b. if choice2 is "paper", then "paper" wins.

How do we structure this? It's a bit different to what we have already seen. We will first have an if statement. And then the code inside that if statement will be...another if statement!

Under the existing code in the function compare, write an if statement where the condition is choice1 equals "rock".
In the code block for the if statement, write an if / else statement. In that statement, if choice2 is "scissors", return "rock wins". Otherwise, return "paper wins".
hint given:
Code:
This putting if statements inside if statements is a little tricky at first. Below is an outline of what the syntax should look like:

if (condition) {
     if (condition) {
         return "some string";
     } else {
         return "some other string";
}


my code:
Code:
var compare = function(choice1, choice2)
{
	if (choice1 === choice2);
{
	return "The result is a tie!";
} if (choice1 === "rock"):
{
     if (choice2 === "scissors") {
         return "rock wins";
     } else {
         return "paper wins";
     }
} function(compare)
};

error: Did you define a function called compare?


what i do wrong? >:I been stuck on this shit for 3 days -.-
you must define compare first -_-
Quote Originally Posted by Janitor View Post
you must define compare first -_-
i tried function(compare) but it didnt work.. or did i do it wrong

and i did function compare() still didnt work... and where am i suppose to put it? (still newish to java)
A function is called a method in Java. You have to declare the method first.

I'm surprised code academy didn't cover this.
Quote Originally Posted by Lehsyrus View Post
A function is called a method in Java. You have to declare the method first.

I'm surprised code academy didn't cover this.
i did didnt i? and i ask my coder friend and he cant find out how to pass this stage either :I can you tell me wat im suppose to type?
Well the way you are being taught in general is wrong. It isn't showing any of the proper syntax.

I won't give you the answer, instead here is a good tutorial that shows how the syntax will generally need to be formatted.

http://www.tutorialspoint.com/java/java_tutorial.pdf
Quote Originally Posted by Lehsyrus View Post
Well the way you are being taught in general is wrong. It isn't showing any of the proper syntax.

I won't give you the answer, instead here is a good tutorial that shows how the syntax will generally need to be formatted.

http://www.tutorialspoint.com/java/java_tutorial.pdf
idk which part am i suppose to look at
All of it. Just trust me that document will do you better than codeacademy.
Quote Originally Posted by Lehsyrus View Post
All of it. Just trust me that document will do you better than codeacademy.
lol i hate reading but ill read it
Jesus christ. Programming section.
Quote Originally Posted by Auxilium View Post
Jesus christ. Programming section.
nah.. it dont get enough views there for help
Codecademy teaches JavaScript, not Java. Get it right, they're 2 different things.

Under the existing code
What the fuck did you do the existing code.
Quote Originally Posted by master131 View Post
Codecademy teaches JavaScript, not Java. Get it right, they're 2 different things.



What the fuck did you do the existing code.

this
if (choice1 === "rock"):
{
if (choice2 === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
} function(compare)
};
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us