Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ROSHAMBO BITCHES!
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//JavaScript-C24.2.0 (SpiderMonkey) var compare = function(choice1, choice2){ if (choice1 === "rock"){ if(choice2 === "scissors"){ return "rock wins"; }else if(choice2 === "rope"){ return "rope wins"; }else{ return "paper wins"; } }else if (choice1 === "paper"){ if(choice2 === "rock"){ return "paper wins"; }else if(choice2 === "rope"){ return "rope wins"; }else{ return "scissors wins"; } }else if (choice1 === "scissors"){ if(choice2 === "rock"){ return "rock wins"; }else if(choice2 === "rope"){ return "rope wins"; }else{ return "scissors wins"; } }else if (choice1 === "rope"){ if(choice2 === "rope"){ return "player rope wins"; }else{ return choice2+" wins"; } } else{ return "Invalid answer!"; } }; var tie = true; while (tie === true){ var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.floor(Math.random()*4); if (computerChoice === 0) { computerChoice = "rock"; } else if(computerChoice === 1) { computerChoice = "paper"; } else if(computerChoice === 2) { computerChoice = "scissors"; } else if(computerChoice === 3) { computerChoice = "rope"; } console.log("User: " + userChoice); console.log("Computer: " + computerChoice); if (userChoice === computerChoice && userChoice != "rope" && computerChoice != "rope"){ tie = true; prompt ("The result is a tie!"); }else{ tie = false; compare(userChoice, computerChoice); } }
[
+
]
Show input
edit mode
|
history
|
discussion