Skip to content
Open
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
181 changes: 165 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)

//declare a variable
//use if else statement
//true if age is greater than 18
const votingAge = 19;



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)


var a = 15;
var b = 30;

if (a === 10) {
console.log("True!");
} else {
console.log("False!");
}


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

// NOTES
//Declare a variable "1999"
//Write a console to equal 1999
var num = "1999";

console.log(num);



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

function Multiply(a, b){
var a = 2
var b = 3
console.log(a * b)
}




Expand All @@ -27,8 +50,11 @@
//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

function dogYears(age){
return Math.pow(age,7);
}


console.log(dogYears(25));


/************************************************************** Task 3 **************************************************************/
Expand All @@ -49,55 +75,181 @@

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

// NOTES
//Takes weight in pounds
//Age in years (puppy in decimal; dog as integers)
//Returns the number of pounds of raw food to feed in a day

let age = 1
let weight = 15

function feedTheDog(age, weight){
if(age >= 1 && weight <= 5){
return weight * 0.05;
} else if (weight <= 10){
return weight * 0.04;
} else if (weight <= 15){
return weight * 0.3;
} else (weight >= 15)
return weight * 0.2;
}
feedTheDog(1, 15);



/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
// Your function should take a string (either rock paper or sissors)
// Rock, Paper, Scissors
// Your function should take a string (either rock paper or scissors)
// 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


// NOTES
//function is mentioned
//return you won or lost
//use math.random to determine random handSymbols
//equate choice to a number (integer)
//****Rules of the Game***//
//scissors vs. rock = lost
//scissors vs. paper = win
//scissors vs. scissors = draw
//rock vs. scissors = win
//rock vs. paper = lost
//rock vs. rock = draw
//paper vs. scissors = lost
//paper vs. rock = win
//paper vs. paper = draw

const rock = "r";
const paper = "p";
const scissors = "s";
var random = Math.floor(Math.random() * 60) + 1;

function handSymbol(rock, paper, scissors){
if(rock === r){
return "draw";
} else if (rock === p){
return "lost";
} else if (rock === s){
return "win";
} else if (paper === p){
return "draw";
} else if (paper === s){
return "lost";
} else if (paper === r){
return "win";
} else if (scissors === s){
return "draw";
} else if (scissors === r){
return "lost"
} else if (scissors === p){
return "win"
}
}
console.log(random)




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


// NOTES
//make 1.60934 kilometers = 1 mile

// let kilometers = 1.60934

// function miles(kilometers){
// Divide(miles / 1.60934)
// }

// console.log(3 / kilometers)

var kilometers = parseInt(prompt("Please enter amount of kilometers:"));
var miles = kilometers / 1.6;
console.log(miles + " Miles");



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


var feet = parseInt(prompt("Please enter amount of feet that you would like to convert:"));
var cm = feet * 30.48;
console.log(cm + " 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`



function annoyingSong(){
var bottles;
var bottlesLeft;
for (i = 99; i >= 1; i--){
if (i == 1){
bottles = "bottle";
bottlesLeft = "No bottles of soda on the wall";
} else {
bottles = "bottles";
bottlesLeft = i -1 + "bottles of soda on the wall";
} console.log(1+ " " + bottles + " of soda on the wall,");
console.log("Take one down, pass it around,");
console.log(bottlesLeft);
}
}

console.log(annoyingSong());


/************************************************************** 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
//70s should be C
//60s should be D
//and anything below 60 should be F




// NOTES
//that takes = function
function myGrade(x){
let grade;
switch (x) {
case x >= 90:
grade = "A";
return grade

case x >= 80:
grade = "B";
return grade

case x >= 70:
grade = "C";
return grade

case x >= 60:
grade = "D";
return grade

case x < 59:
grade = "F";
return grade
}
return grade
}
console.log(myGrade(87))

// NOTES
/* Caveman vs Spaceman
1. Plan english(native language too!)
2. Try to solve the problem in your own words
3. Start coding! Don't over think it or over optimize it at this point
4. Once it's working, look at some optimizations (in a few weeks!)
*/

/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
Expand All @@ -113,6 +265,3 @@
//update your rock papers sissors code below to take a prompt from a user using the window object