-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c52f8b2
commit c167552
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
let question = 'Will I master JS?'; | ||
let answer = ''; | ||
|
||
let randomNumber = Math.floor(Math.random() * 9) + 1; | ||
|
||
switch (randomNumber) { | ||
case 1: | ||
answer = 'Yes - definitely.'; | ||
break; | ||
case 2: | ||
answer = 'It is decidedly so.'; | ||
break; | ||
case 3: | ||
answer = 'Without a doubt.'; | ||
break; | ||
case 4: | ||
answer = 'Reply hazy, try again.'; | ||
break; | ||
case 5: | ||
answer = 'Ask again later.'; | ||
break; | ||
case 6: | ||
answer = 'Better not tell you now.'; | ||
break; | ||
case 7: | ||
answer = 'My sources say no.'; | ||
break; | ||
case 8: | ||
answer = 'Outlook not so good.'; | ||
break; | ||
case 9: | ||
answer = 'Very doubtful.'; | ||
break; | ||
default: | ||
answer = 'Program error.'; | ||
break; | ||
} | ||
|
||
console.log(`Question: ${question}`); | ||
console.log(`Magic 8 Ball: ${answer}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
let player = 'Rock'; | ||
let playerPick = ''; | ||
|
||
if (player === 'Rock' || player === 'rock') { | ||
playerPick = 0; | ||
} else if (player === 'Paper' || player === 'paper') { | ||
playerPick = 1; | ||
} else if (player === 'Scissors' || player === 'scissors'){ | ||
playerPick = 2; | ||
} else { | ||
console.log('Wrong input. Select rock, paper or scissors.'); | ||
} | ||
|
||
let computer = ''; | ||
let computerPick = Math.floor(Math.random()*3); | ||
|
||
if (computerPick === 0) { | ||
computer = 'Rock'; | ||
} else if (computerPick === 1) { | ||
computer = 'Paper'; | ||
} else if (computerPick === 2) { | ||
computer = 'Scissors'; | ||
} else { | ||
console.log('Error in computer pick generation.'); | ||
} | ||
|
||
console.log(`Player picked: ${player}`) | ||
console.log(`Computer picked: ${computer}`) | ||
console.log(''); | ||
|
||
if (playerPick === 0) { | ||
if (computerPick === 0) { | ||
console.log('Draw.'); | ||
} else if (computerPick === 1) { | ||
console.log('Computer won!'); | ||
} else if (computerPick === 2) { | ||
console.log('Player won!'); | ||
} else { | ||
console.log('Error. Impossible to calculate the result.') | ||
} | ||
} else if (playerPick === 1) { | ||
if (computerPick === 0) { | ||
console.log('Player won!'); | ||
} else if (computerPick === 1) { | ||
console.log('Draw.'); | ||
} else if (computerPick === 2) { | ||
console.log('Computer won!'); | ||
} else { | ||
console.log('Error. Impossible to calculate the result.') | ||
} | ||
} else if (playerPick === 2) { | ||
if (computerPick === 0) { | ||
console.log('Computer won!'); | ||
} else if (computerPick === 1) { | ||
console.log('Player won!'); | ||
} else if (computerPick === 2) { | ||
console.log('Draw'); | ||
} else { | ||
console.log('Error. Impossible to calculate the result.') | ||
} | ||
} |