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
131 changes: 126 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)
let votingAge = 25
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)
let hour = 20
let lost = 2
if (hour < 18) {
newtime = hour - lost;
} else {
newtime = hour + lost;
}

console.log(newtime)




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



//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method
let num = Number ("1999");
console.log(num)


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

let a = 7
let b = 22

console.log (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


let myAge = 31;
let myAgeInDogYears = (myAge *7)
console.log(myAgeInDogYears)



Expand All @@ -49,7 +65,25 @@

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


function dogFeeder(weight,age){
if(age >= 1){
if (weight <= 5){
let amount = weight * 0.05;
return amount
}else if (weight >= 6 && weight <= 10){
let amount = weight * 0.04;
return amount
}else if (weight >= 11 && weight <= 15){
let amount = weight * 0.03;
return amount
}else{
let amount = weight * 0.02
return amount
}
}

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



Expand All @@ -60,6 +94,57 @@
// 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

// let userChoice = prompt("Do you choose rock, paper or scissors?");


function rockpaperscissors(userChoice = ""){

let computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}

function compare(userChoice, computerChoice) {
if(userChoice === computerChoice) {
return "The result is a tie!";
}

if (userChoice === "rock") {
if(computerChoice === "scissors") {
return "You win!";
} else {
return "You lose!";
}
}
if (userChoice === "paper") {
if (computerChoice === "rock") {
return "You win!";
} else {
if (computerChoice === "scissors") {
return "You lose!";
}
}
if (userChoice === "scissors") {
if (computerChoice === "rock") {
return "You Lose!";
} else {
if (computerChoice === "paper") {
return "You Win!";
}
}
}
}
};
console.log("User Choice: " + userChoice);
console.log("Computer Choice: " + computerChoice);
console.log(compare(userChoice, computerChoice));
}

console.log(rockpaperscissors("rock"))



Expand All @@ -68,20 +153,37 @@
//a. KM to Miles - should take the number of kilometers and convert it to the equal number of miles


let kilo = 30
let mile = .621371

console.log(kilo*mile + " miles")




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

let feet = 71
let centimeters = 30.48

console.log(feet*centimeters + " 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`


let text = "";
let i;
for (i = 2; i > 0; i--) {
text += i + " Bottles of soda on the wall, " + i + " Bottles of soda, take one down pass it around " + (i-1) + " bottles of soda on the wall.";

}

console.log(text)



Expand All @@ -96,6 +198,25 @@
//and anything below 60 should be F



function gradeCalculator(score){
if (score >= 90){
return "A";
}else if(score <= 89 && score >= 80){
return "B";
}else if(score <= 79 && score >= 70){
return "C";
}else if(score <= 69 && score >= 60){
return "D";
}else{
return "F";
}

}

console.log(gradeCalculator(88))





Expand Down