Skip to content
Open
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
141 changes: 129 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

let votingAge;

if (votingAge >=18 ) {
console.log(true);
}



//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 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)

let weekend = 2;
const vacation_weekend = 3;
let vacation = true;

if (vacation){
weekend = vacation_weekend;
}

//DO DIFFERENT

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


Number("1999");



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



const arrowFunction = (a,b) => {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


const arrowFunction2 = (humanAge) => {humanAge * 7};




Expand All @@ -49,8 +63,37 @@

// 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



let dogAge;
let dogWeight;

function dogFeeder(dogAge,dogWeight) {
if (dogAge >= 1 ){
{
if (dogWeight > 15){
return dogWeight*.02;
} else if (dogWeight >= 11){
return dogWeight*.03;
} else if (dogWeight >= 6){
return dogWeight*.04;
} else {
return dogWeight*.05;
}
}
} else {
if (dogAge >= (7/12)){
return dogWeight*.04;
} else if (dogAge >= (4/12)){
return dogWeight*.05;
} else if (dogAge >= (2/12)){
return dogWeight*.1;
} else {
return null;
}
}

}

console.log(dogFeeder(1,15));


/************************************************************** Task 4 **************************************************************/
Expand All @@ -60,29 +103,62 @@
// 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




function compPlays(){
let roboChoice = Math.random();

if (roboChoice < .33) {
roboChoice = "rock";
} else if (roboChoice < .66 ) {
roboChoice = "paper";
} else {
roboChoice = "scissors";
}
return roboChoice;
}

function rockPaperScissors(choice) {
const roboChoice = compPlays();

if (choice === roboChoice){
return "Tie."
}
else if (choice === "rock" && roboChoice === "scissors" ||
choice === "scissors" && roboChoice === "paper" ||
choice === "paper" && roboChoice === "rock") {
return "You won.";
} else {
return "You lost.";
}
}


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



const arrowFunction3 = (distance) => distance * 0.62137119224;


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



const arrowFunction4 = (length) => length*30.48;


/************************************************************** 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`


function annoyingSong(bottleNum) {
while (bottleNum > 0) {
console.log(`${bottleNum} bottles of soda on the wall, ${bottleNum} bottles of soda, take one down pass it around ${bottleNum-1} bottles of soda on the wall`);
bottleNum--;
}
}



Expand All @@ -94,9 +170,20 @@
//70s should be Cs
//60s should be D
//and anything below 60 should be F



function letterGrade(grade) {
if (grade >= 90) {
return "A";
} else if (grade >=80){
return "B";
} else if (grade >=70){
return "C";
} else if (grade >=60){
return "D";
} else{
return "F";
}
}


/************************************************************** Stretch **************************************************************/
Expand All @@ -112,7 +199,37 @@
//Take Rock, Paper, Sissors further
//update your rock papers sissors code below to take a prompt from a user using the window object


function compPlays(){
let roboChoice = Math.random();

if (roboChoice < .33) {
roboChoice = "rock";
} else if (roboChoice < .66 ) {
roboChoice = "paper";
} else {
roboChoice = "scissors";
}
return roboChoice;
}

let choice = prompt("Choose: rock, paper, or scissors");

function updated_rockPaperScissors(choice) {
const roboChoice = compPlays();

if (choice === roboChoice){
return "Tie."
}
else if (choice === "rock" && roboChoice === "scissors" ||
choice === "scissors" && roboChoice === "paper" ||
choice === "paper" && roboChoice === "rock") {
return "You won.";
} else {
return "You lost.";
}
}

console.log(updated_rockPaperScissors(choice));