RetroHat
|
  |
| Joined: 22 Oct 2011 |
| Total Posts: 12347 |
|
|
| 06 Dec 2014 02:52 PM |
ot: offers on 243 R$ --------------------- Game works perfectly, but how do I make it so the answer isn't caps sensitive?
Ex.
If I picked "rock", the game would work out perfectly.
If I picked "ROCK", the game wouldn't work out as perfectly because it is caps sensitive.
--------------
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") { if (choice2 === "scissors") { return "rock wins" } else { return "paper wins" } } else if (choice1 === "paper") { if (choice2 === "rock") { return ("paper wins") } else { return "scissors wins" } } };
compare(userChoice, computerChoice)
|
|
|
| Report Abuse |
|
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
| |
|
|
| 06 Dec 2014 02:57 PM |
var e1 = "Hello World!"; var e2 = str.toLowerCase(); also send trades / 59k/?? |
|
|
| Report Abuse |
|
|
xSQLi
|
  |
| Joined: 31 Oct 2014 |
| Total Posts: 633 |
|
| |
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
|
| 06 Dec 2014 02:58 PM |
where do i add that @ coin
on top? |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 02:58 PM |
use answer.toLowerCase();
also send trades / 59k/?? |
|
|
| Report Abuse |
|
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
|
| 06 Dec 2014 02:58 PM |
@xsql
thx i am like 1/4 of the way done
|
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 02:59 PM |
var userChoice = prompt("Do you choose rock, paper or scissors?"); userChoice = userChoice.toLowerCase(); 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") { if (choice2 === "scissors") { return "rock wins" } else { return "paper wins" } } else if (choice1 === "paper") { if (choice2 === "rock") { return ("paper wins") } else { return "scissors wins" } } };
compare(userChoice, computerChoice) also send trades / 59k/?? |
|
|
| Report Abuse |
|
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
| |
|
Acmic
|
  |
| Joined: 04 Oct 2008 |
| Total Posts: 47963 |
|
| |
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
|
| 06 Dec 2014 03:06 PM |
@dylan
other one looks simpler
;C |
|
|
| Report Abuse |
|
|
Acmic
|
  |
| Joined: 04 Oct 2008 |
| Total Posts: 47963 |
|
|
| 06 Dec 2014 03:10 PM |
Well, people are humans
Cant expect them to be as perfect as a computer
With the other one:
>inputs "Rock "
>breaks because of the space
With mine anything including the word "rock" is taken as rock
And it u needed it to be specifically rock, paper, or scissors
userChoice = (!!userChoice.match(/rock/i) ? "rock":!!userChoice.match(/paper/i) ? "paper":"scissors") |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 03:13 PM |
@dylan
userChoice.indexof("rock")
ik i didnt captialized indexof corect but watevr
also send trades / 59k/?? |
|
|
| Report Abuse |
|
|
curve8900
|
  |
| Joined: 23 May 2009 |
| Total Posts: 4401 |
|
|
| 06 Dec 2014 03:14 PM |
ya i was going to like try and make something like
if (userChoice =/= "rock","paper","scissors") { prompt("Do you choose rock, paper or scissors?") }
idk how to make a not equal sign though =/= doesnt work
but acmin why are there those like "!!" and crap and /i and stuffz
|
|
|
| Report Abuse |
|
|
Acmic
|
  |
| Joined: 04 Oct 2008 |
| Total Posts: 47963 |
|
|
| 06 Dec 2014 03:14 PM |
dont u mean if(userChoice.toLowerCase().indexOf("rock") > -1)
isnt !!userChoice.match(/rock/i) a lot simpler? |
|
|
| Report Abuse |
|
|
Sinblade
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 2782 |
|
|
| 06 Dec 2014 03:15 PM |
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"){ if (choice2 === "scissors"){ return("Rock Wins!") } else { return("Paper Wins!") } } else if (choice1 === "paper"){ if (choice2 === "rock"){ return("Paper Wins!") } else{ return("Scissors Win!") } } } compare(userChoice, computerChoice)
calculators are for dummies |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 03:15 PM |
no cuz idk how to do that !!aduiwhaw:"" thing also send trades / 59k/?? |
|
|
| Report Abuse |
|
|
Acmic
|
  |
| Joined: 04 Oct 2008 |
| Total Posts: 47963 |
|
|
| 06 Dec 2014 03:19 PM |
Not sure how to explain the !!, it turns anything into a boolean
the i means case-insensitive |
|
|
| Report Abuse |
|
|