Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
header {
text-align: center;
margin-top: 20vh;
}

header h1 {
font-size: 4rem;
}

section {
margin-top: 8vh;
text-align: center;
}

section p {
font-size: 1.5rem;
}

section h3 {
font-size: 2rem;
}

#computerPlayed {
text-transform: capitalize;
}
32 changes: 23 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="index.css" />
<title>Rock Paper Scissors</title>
</head>
<body>
<header>
<h1>ROCK PAPER SCISSORS!</h1>
</header>

<section>
<h3>Results</h3>
<p id="results">text</p>
<h3>Opponent Played</h3>
<p id="computerPlayed">text</p>
</section>

<button onclick="window.location.reload();">Try again</button>

<script src="index.js"></script>
</body>
</html>
163 changes: 45 additions & 118 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,45 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)





//Task b: declare a variable and then use a conditional to change the value of that variable based on the value assigned to a second variable (no function required)





//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method





//Task d: Write a function to multiply a*b





/************************************************************** Task 2 **************************************************************/
//Age in Dog years
//write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years





/************************************************************** Task 3 **************************************************************/
//Dog feeder
//takes weight in pounds and age in years (note if the dog is a puppy the age will be a decimal) and returns the number of pounds of raw food to feed in a day.

//feeding requirements
// adult dogs at least 1 year
// up to 5 lbs - 5% of their body weight
// 6 - 10 lbs - 4% of their body weight
// 11 - 15 lbs - 3% of their body weight
// > 15lbs - 2% of their body weight

// Puppies less than 1 year
// 2 - 4 months 10% of their body weight
// 4 - 7 months 5% of their body weight
// 7 - 12 months 4% of their body weight

// when you are finished invoke your function with the weight of 15 lbs and the age of 1 year - if your calculations are correct your result should be 0.44999999999999996





/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
// Your function should take a string (either rock paper or sissors)
// it should return you won or you lost based on the rules of the game (you may need to look up the rules if you have not played before)
// use math.random to determine the computers choice
// hint while you can complete this with only conditionals based on strings it may help to equate choice to a number




/************************************************************** Task 5 **************************************************************/
//Metric Converter
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles





//b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters





/************************************************************** Task 6 **************************************************************/
// 99 bottles of soda on the wall
// create a function called annoyingSong
// the function should take a starting number as an argument and count down - at each iteration it should log (number) bottles of soda on the wall, (number) bottles of soda, take one down pass it around (number left over) bottles of soda on the wall`





/************************************************************** Task 7 **************************************************************/
//Grade Calculator
//write a javaScript program that takes a mark out of 100 and returns a corisponding letter grade
//90s should be A
//80s should be B
//70s should be Cs
//60s should be D
//and anything below 60 should be F





/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
// Hint - you may need to study tomorrow's traning kit on arrays
// try looking up the .includes() method





/************************************************************** Stretch **************************************************************/
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object





const choices = ['rock', 'paper', 'scissors'];
let cpuChoice = Math.floor(Math.random() * 3);
let playerChoice = prompt('Make your move!').toLowerCase();

if (playerChoice === choices) {
playerChoice === playerChoice;
}

function cpu(cpuChoice) {
if (cpuChoice === 0) {
return choices[0];
} else if (cpuChoice === 1) {
return choices[1];
} else {
return choices[2];
}
}
cpu(cpuChoice);

const win = 'You Win! &#128513';
const lose = 'You lose! &#128547';
const tie = 'Tie!';

function rpsGame(playerChoice) {
if (playerChoice === 'scissors' && cpu(cpuChoice) === 'rock') {
return lose;
} else if (playerChoice === 'rock' && cpu(cpuChoice) === 'scissors') {
return win;
} else if (playerChoice === 'paper' && cpu(cpuChoice) === 'rock') {
return win;
} else if (playerChoice === 'scissors' && cpu(cpuChoice) === 'paper') {
return win;
} else if (playerChoice === 'rock' && cpu(cpuChoice) === 'paper') {
return lose;
} else if (playerChoice === 'paper' && cpu(cpuChoice) === 'scissors') {
return lose;
} else {
return tie;
}
}

rpsGame(playerChoice);

document.getElementById('results').innerHTML = rpsGame(playerChoice);
document.getElementById('computerPlayed').innerHTML = cpu(cpuChoice);