Confused at what is wanted here

#1

I'm unsure as to what I'm supposed to do. This confuses me. Any assistance?

No error

``````var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function (choice1, choice2) {

if(choice1 === choice2) {
return "The result is a tie!"
} else if (choice1 === "rock") { // 1st else if condition braces start
if(choice2 === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
} // 1st else if condition braces close
else if (choice1 === "paper") { // 2nd else if condition braces start
if (choice2 === "rock") {
return "paper wins";
} else {
return "scissors wins";
}
} // 2nd else if condition braces close
else if (choice1 === "scissors") { // 3rd else if condition braces start
if (choice2 === "rock") {
return "rock wins";
} else {
return "scissors wins";
}
}  // 3rd else if condition braces close

};``````

#2

What error message are you getting?

#3

I don't get an error message. I'm just completely confused as to what this exercise wants done.

#4

The exercise from start to end or just this section? For this section, you write code to allow for outcomes dependent on choice1 === "scissors".

#5

It's just the section within the link. I'm used to using c++ to do if/else loops. This method used here seems wacky to me. Can you please explain?

#6

I don't have a background in c++. Just a rookie getting his feet wet in this javascript course. Wouldn't want to steer you in the wrong direction. I think one of the moderators would be better qualified to articulate similarities/differences between c++ and javascript.

#7

if/else/for behave mostly the same in C and JavaScript (and if/else doesn't make a loop, at least not on its own)

You really haven't described what the problem is, there appears to be nothing for anyone to help you along with. You say there's no error, which at least I will read as "There's no problem here, please help."

If there's something you want to discuss, make it abundantly clear what that something is. You can for example write a minimal piece of code (you posted quite a few lines that don't seem to showing anything in particular) that contains whatever it is you have a question about, and you can explain your thoughts around the topic such as what you expect and what is different from that.

#8

My problem is I don't understand what the exercise here wants me to do. It says to make if/else loops, but I don't understand where, nor the logic behind the loops in this exercise. Sorry if I didn't make that clear. I haven't written any code except for what's already there in the exercise.

#9

That then leaves us wondering what we can say that the instructions have not already!

They say:

else if statement where the condition is choice1 === "paper"

Which tells us we're looking at choice and doing something when it's paper, and then:

Inside this else if statement, write an if / else statement. If choice2 === "rock", return "paper wins". Else, return "scissors wins".

Which is looking at choice2, taking the appropriate actions based on its value

Perhaps you just need to read over the instructions a few more times/more carefully? If so do that instead of posting a vague question. That's not to discourage you from asking, but that is what it looks like you're best off doing, at least until you add information saying otherwise. Maybe you just need a nudge/confirmation that studying the instructions closer is the thing to do. Sometimes the instructions demand that you spend a bit more time with them than you might with other text, particularly since they describe something you must follow exactly.

Knowing how the game rock paper scissors works also says quite a lot about what this function should be doing.

#10

@ionatan it makes sense. Thanks for the information. I think my issue is I don't quite get where exactly the code goes. I will spend more time and take a look at it over the weekend.

#11

@ionatan Thank you again for the information. I finally figured it out. I literally had to go item by item which apparently is a problem to me. This has been solved! I just made the loops where it stated to and it works!

#12

The function runs from top to bottom and needs to do certain operations to end up with the desired result. Those operations are the same as what you need to do while manually playing the game which should make it easy to follow along and therefore also figure out what goes where.

The exercise appears to be about managing lots of if-statements, if that's the trouble then you appear to be in just the right place. Perhaps you'll want to experiment with even simpler cases in a separate piece of code so that you can experiment with more isolated use of if-statements.

(There are much better ways to describe the rules of rock paper scissors, all it takes is to consider how you do it manually, particularly how you would explain the rules to somebody else which doesn't involve explaining every single combination)

#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.