-2

The console states that there is an unexpected { in my code. I went over the syntax several times and cannot seem to find it.

var userChoice = prompt("Do you choose rock, paper, or scissors?");

var computerChoice = Math.random(1);

if (computerChoice <= 0.33){
    computerChoice = "rock";
} elseif (computerChoice <= 0.67 && computerChoice >= 0.34) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
eagercoder
  • 526
  • 1
  • 10
  • 23
  • 1
    `else if`, not `elseif` – j08691 Jul 17 '15 at 00:29
  • @j08691: Answer, not comment. – Lightness Races in Orbit Jul 17 '15 at 00:29
  • @LightnessRacesinOrbit - It's a typo, vote to close -- don't answer. – j08691 Jul 17 '15 at 00:30
  • 1
    @j08691: _You_ answered! In the wrong place... Double wrong by your logic. Furthermore, how do you know it's a typo? – Lightness Races in Orbit Jul 17 '15 at 00:30
  • @LightnessRacesinOrbit - I voted to close as a typo *and* pointed out the problem o the user wasn't left wondering why. I could answer and mark it as a community wiki though. And it's a typo, regardless if it was intentional or not. Questions like these don't need formal answer and should be closed. – j08691 Jul 17 '15 at 00:31
  • So you say "don't answer" but also provide an answer...... I don't get that. At all. If you think the question doesn't belong here then _don't answer it whatsoever, at all_. Certainly, though, it goes back to this for me: answers do not go in comments. Ever. And as for your "typo" comment that is simply nonsense: typos are by definition unintentional. I think you're mistaking "very small, isolated misunderstanding or error" with this invented "unintentional typo"! :) – Lightness Races in Orbit Jul 17 '15 at 00:33
  • @LightnessRacesinOrbit - I don't see what you're getting so upset about, but whatever. – j08691 Jul 17 '15 at 00:33
  • @j08691: I'm not "so upset" about anything; I'm trying to have a rational conversation with you about how the Stack Exchange Q&A model works, and I'm trying to decipher some of the things you're saying in response (many of which are contradictory, as I've pointed out). "But whatever." – Lightness Races in Orbit Jul 17 '15 at 00:34
  • @LightnessRacesinOrbit - http://www.merriam-webster.com/dictionary/typo. I don't see that it has to be "unintentional" (Waits for mod to come through and delete this whole comment thread) – j08691 Jul 17 '15 at 00:36
  • @j08691: By the logic with which you interpret that dictionary entry, literally every programming mistake in the world is a "typo"! (Passive aggression doesn't suit you, sir!) – Lightness Races in Orbit Jul 17 '15 at 00:38
  • @LightnessRacesinOrbit - settle this over a beer? – j08691 Jul 17 '15 at 00:42
  • @LightnessRacesinOrbit comments are not meant for discussions either. That's what the chat is for. – Sebastian Nette Jul 17 '15 at 00:48
  • @SebastianNette: Right, so why are you joining in a discussion in the chat section? :) See it's really easy to get drawn in. These can all be deleted now. I just wanted to point out, alongside where it happened, that an answer in the comment section is bad. That's it. That's all. None of all this drama business is required. – Lightness Races in Orbit Jul 17 '15 at 09:43

3 Answers3

1

It should be else if (not together)

EDIT: This is the working code

var userChoice = prompt("Do you choose rock, paper, or scissors?");

var computerChoice = Math.random(1);

if (computerChoice <= 0.33){
    computerChoice = "rock";
} else if (computerChoice <= 0.67 && computerChoice >= 0.34) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
leo.fcx
  • 6,137
  • 2
  • 21
  • 37
1

elseif should have space in between.

var userChoice = prompt("Do you choose rock, paper, or scissors?");

var computerChoice = Math.random(1);

if (computerChoice <= 0.33){
    computerChoice = "rock";
} else if (computerChoice <= 0.67 && computerChoice >= 0.34) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
Diwas
  • 733
  • 6
  • 12
0

The problem is that you made up the keyword elseif, likely intending else if.

For future reference, the console also tells you which line the error is on; it's fairly easy after that to investigate each piece of technology on that line (check your spelling, look up meanings, etc.) to discover what you did wrong. In this case a very quick Google search for "javascript elseif" gets you there.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055