Skip to content

Commit

Permalink
new js progs
Browse files Browse the repository at this point in the history
  • Loading branch information
jemappellen committed Feb 20, 2025
1 parent c52f8b2 commit c167552
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
40 changes: 40 additions & 0 deletions codédex-projects/JS projects/magic8ball.js
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}`);
61 changes: 61 additions & 0 deletions codédex-projects/JS projects/rock-paper-scissors.js
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.')
}
}

0 comments on commit c167552

Please sign in to comment.