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}"
}
]
}
138 changes: 114 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)




const votingAge = 18
console.log(votingAge >= 18)

//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 fruit1 = "Apple";
let isTasty = "Yum";

if(isTasty === "Yuk"){
fruit1 = "Delicious";
}else {
fruit1 = "Gross";
}


console.log(fruit1);

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




let a = parseInt("1999")
console.log(a)

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




const multiplyArrow = (a, b) => {
return a * b;
}
console.log(multiplyArrow(4, 5))

/************************************************************** 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 dogCalc = (myAge, dogYears) => {
return myAge * dogYears;
}
console.log(dogCalc(19, 7))

/************************************************************** Task 3 **************************************************************/
//Dog feeder
Expand All @@ -49,8 +56,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 hungryDog(weight, age){
if(age >= 1 && weight <= 5){
return weight * 0.05
} else if(age >= 1 && weight >= 6 && weight <= 10){
return weight * 0.04
} else if(age >= 1 && weight >= 11 && weight <= 15){
return weight * 0.03
} else if(age >= 1 && weight > 15){
return weight * 0.02
} else if(age >= 0.166667 && age <= 0.333333){
return weight * 0.10
} else if(age >= 0.333333 && age <= 0.583333){
return weight * 0.05
} else if(age >= 0.583333 && age <= 1){
return weight * 0.04
}
}

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


/************************************************************** Task 4 **************************************************************/
Expand All @@ -60,20 +84,65 @@
// 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


var myChoice=prompt("Choose rock, paper, or scissors");
var cpu=Math.random();
if(cpu < 0.34) {
cpu = "rock";
} else if(cpu <= 0.67){
cpu = "paper";
} else {
cpu = "scissors";
}

var compare = function(choice1, choice2){
if(choice1 === choice2){
return "It's a tie!"
}
if(choice1 === "rock"){
if(choice2 === "scissors") {
return "You win! CPU chose Scissors."
} else {
return "You lose! CPU chose Paper."
}
}
if(choice1 === "paper"){
if(choice2 === "rock"){
return "You win! CPU chose Rock."
} else {
if(choice2 === "scissors"){
return "You lose! CPU chose Scissors."
}
}
}
if (choice1 === "scissors"){
if(choice2 === "paper"){
return "You win! CPU chose paper."
}
if(choice2 === "rock"){
return "You lose! CPU chose rock."
}
}
}
compare(myChoice, cpu)


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


function km2m(kilometers){
return kilometers * 0.62137
}
km2m(2)



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


function ft2cm(feet){
return feet / 0.032808
}
ft2cm(2)



Expand All @@ -83,21 +152,42 @@
// 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`


var newnum = -1;
function annoyingSong(bottles) {
for(let i = 99; i >= 1; i--) {
console.log(i + " bottles of soda on the wall, " + i + " bottles of soda, take one down pass it around. " + (i+newnum) + " bottles of soda on the wall")
}
}
annoyingSong(99)



/************************************************************** 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
//90s should be As
//80s should be Bs
//70s should be Cs
//60s should be D
//and anything below 60 should be F


//60s should be Ds
//and anything below 60 should be Fs

function grades(number) {
if(number >= 90 && number <= 100){
return "A"
} else if(number >= 80 && number < 90){
return "B"
} else if(number >= 70 && number < 80){
return "C"
} else if(number >= 60 && number < 70){
return "D"
} else if(number < 60){
return "F"
} else {
return "Please use a number between 0 and 100"
}
}

console.log(grades(100));

/************************************************************** Stretch **************************************************************/
//Create a function that counts the number of vowels within a string. It should handle both capitalized and uncapitalized vowels.
Expand Down