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
46 changes: 22 additions & 24 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
import functions from '../index';

describe('fooFunction', ()=>{
it('foo returns foo', ()=>{
describe('fooFunction', () => {
it('foo returns foo', () => {
expect(functions.foo()).toBe('bar');
})
});

describe('multiplyFunction', ()=>{
it('a * b', ()=>{
describe('multiplyFunction', () => {
it('a * b', () => {
expect(functions.multiply(5, 7)).toBe(35);
})
});

describe('dogYearsFunction', ()=>{
it('returns humanYears * 7', ()=>{
describe('dogYearsFunction', () => {
it('returns humanYears * 7', () => {
expect(functions.dogYears(5)).toBe(35);
})
});

describe('hungryDogFunction', ()=>{
it('returns weight * x based on age and weight', ()=>{
describe('hungryDogFunction', () => {
it('returns weight * x based on age and weight', () => {
expect(functions.hungryDog(15, 1)).toBe(0.44999999999999996);
})
});
describe('gameFunction', ()=>{
it('return win, lose or tie', ()=>{
expect(functions.game('rock', 'sissors')).toBe('you win!');
describe('gameFunction', () => {
it('return win, lose or tie', () => {
expect(functions.game('rock', 'scissors')).toBe('you win!');
})
it('return win, lose or tie', ()=>{
it('return win, lose or tie', () => {
expect(functions.game('rock', 'paper')).toBe('you lose!');
})
it('return win, lose or tie', ()=>{
it('return win, lose or tie', () => {
expect(functions.game('rock', 'rock')).toBe(`it's a tie`);
})
});
describe('milesFunction', ()=>{
it('return km * 0.621371', ()=>{
describe('milesFunction', () => {
it('return km * 0.621371', () => {
expect(functions.miles(10)).toBe(6.21371);
})
});

describe('feetFunction', ()=>{
it('return cm / 30.48', ()=>{
describe('feetFunction', () => {
it('return cm / 30.48', () => {
expect(functions.feet(160)).toBe(5.2493438320209975);
})
});
describe('annoyingSongFunction', ()=>{
it('a string that counts down based on the number imputted', ()=>{
describe('annoyingSongFunction', () => {
it('a string that counts down based on the number imputted', () => {
expect(functions.annoyingSong(5)).toBe(`${5} bottles of soda on the wall, ${5} bottles of soda, take one down pass it around ${5 - 1} bottles of soda on the wall`);
})
});
describe('gradeFunction', ()=>{
it('return letter grade based on number', ()=>{
describe('gradeFunction', () => {
it('return letter grade based on number', () => {
expect(functions.grade(85)).toBe('you got a B');
})
});


});
199 changes: 142 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Do the following:

HINT: no function required
*/


const votingAge = 22; // sets votingAge to 22
if (votingAge >= 18) { // votingAge has to be greater than or equal to 18 to be true, or else it will be false
console.log(true);
}

/*
Task 1b - Values
Expand All @@ -30,9 +32,12 @@ Do the following:

HINT: no function required
*/



let variable1 = 1;
let variable2 = 2;
if (variable2 === 2) { // since variable2 does equal 2, the new value for variable1 will be logged
variable1 = 3;
console.log(variable1);
}


/*
Expand All @@ -45,7 +50,13 @@ Do the following:

HINT: look up the Number method
*/

let stringValue = '1999';
let numValue = parseInt(stringValue, 10); // best practice is to always pass the radix, decimal system uses a radix of 10
if (numValue === 1999) {
console.log(numValue)
} else {
console.error('Did not get expected result');
}



Expand All @@ -58,11 +69,11 @@ Do the following:
3. Multiply a and b and return the answer
*/

function multiply(/*add your code here*/){
/*add your code here*/
}

function multiply(a, b) {
return a * b;
}

console.log(multiply(5, 4));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -74,11 +85,11 @@ Do the following:
3. Return the newly calculated age
*/

function dogYears(/*add your code here*/){
/*add your code here*/
function dogYears(age) {
return age * 7;
}


console.log(dogYears(11));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -105,33 +116,74 @@ Use the hungryDog function and feeding requirements below to do the following:
7 - 12 months 4% of their body weight

NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996
*/
*/

function hungryDog(/*add your code here*/){
/*add your code here*/
}
function hungryDog(weightInPounds, ageInYears) {
if (ageInYears >= 1) {
if (weightInPounds > 15) {
return weightInPounds * .02;
} else if (weightInPounds > 10) {
return weightInPounds * .03;
} else if (weightInPounds > 5) {
return weightInPounds * .04;
} else {
return weightInPounds * .05;
}
} else { //Young dog
if (ageInYears >= 7 / 12) { //7 months is 7/12
return weightInPounds * .04;
} else if (ageInYears >= 4 / 12) {
return weightInPounds * .05;
} else {
return weightInPounds * .1;
}

}
}

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


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

// Rock, Paper, Scissors - Let's play against the computer!
/*
Create a global variable that randomly generates the computer's choice
Use Math.random to determine the computers choice (Math.random gives a random number between 0 and 1)
Use the game function below to do the following:
1. Receive a string that represents the user's choice (either "rock", "paper", or "scissors")
2. Use Math.random to determine the computers choice (Math.random gives a random number between 0 and 1)
3. Return whether the user won, lost, or tied based on these rules of the game described below

1. Receive 2 parameters the user's choice and the computer's choice
2. Return whether the user won, lost, or tied based on these rules of the game described below
RULES OF THE GAME: Scissors beats Paper | Paper beats Rock | Rock beats Scissors | Or there's a tie

HINT: While you can complete this with only conditionals based on strings, it may help to equate choice to a number when using Math.random()
*/

function game(/*add your code here*/){
/*add your code here*/
let comChoice = Math.floor(Math.random() * 3.0); //assign 0, 1, or 2. Math.floor returns the largest integer less than or equal to a given number.

const rock = 'rock';
const paper = 'paper';
const scissors = 'scissors';

function game(userChoice, computerChoice) {
//console.log('userChoice=' + userChoice + ' computerChoice=' + computerChoice);
//console.log('rock=0, paper=1, scissors=2');
if (userChoice === computerChoice) {
return `it's a tie`;
} else if (userChoice === rock && computerChoice === scissors) {
return 'you win!';
} else if (userChoice === paper && computerChoice === rock) {
return 'you win!';
} else if (userChoice === scissors && computerChoice === paper) {
return 'you win!';
} else {
return 'you lose!';
}
}
if (comChoice === 0) {
console.log(game(paper, rock));
} else if (comChoice === 1) {
console.log(game(paper, paper));
} else {
console.log(game(paper, scissors));
}




/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -144,11 +196,11 @@ Using the miles function below do the following:
3. Return the number of miles
*/

function miles(/*add your code here*/){
/*add your code here*/
}

function miles(km) {
return km * 0.621371;
}

console.log(miles(5));

//Task 5b - Feet to CM
/*
Expand All @@ -158,11 +210,11 @@ Using the feet function below do the following:
3. Return number of centimeters
*/

function feet(/*add your code here*/){
/*add your code here*/
}

function feet(cm) {
return cm / 30.48;
}

console.log(feet(10));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -174,10 +226,17 @@ Using the annoyingSong function below do the following:
"(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(/*add your code here*/){
/*add your code here*/
}
function annoyingSong(number) {
return `${number} bottles of soda on the wall, ${number} bottles of soda, take one down pass it around ${number-1} bottles of soda on the wall`;
/*
while (number > 0) {
console.log(`${number} bottles of soda on the wall, ${number} bottles of soda, take one down pass it around ${number-1} bottles of soda on the wall`);
number--; // decreases number 1
}
*/

}
console.log(annoyingSong(5));

/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/

Expand All @@ -193,14 +252,24 @@ Using the grade function below do the following:
60-69 = D
below 60 = F
*/

function grade(/*add your code here*/){
/*add your code here*/
}





function grade(score) {
if (score >= 90) {
return 'you got a A';
} else if (score >= 80) {
return 'you got a B';
} else if (score >= 70) {
return 'you got a C';
} else if (score >= 60) {
return 'you got a D';
} else {
return 'you got a F';
}
}

console.log(grade(100));



/*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/

Expand All @@ -213,21 +282,37 @@ Using the vowelCounter function below do the following:
HINT - you may need to study tomorrow's content on arrays
HINT - try looking up the .includes() method
*/


function vowelCounter(/*add your code here*/) {
/*add your code here*/
let lowerVowels = ['a', 'e', 'i', 'o', 'u'];

function vowelCounter(word) {
let lowerWord = word.toLowerCase();
console.log(lowerWord);
let count = 0;
for (let index = 0; index < lowerWord.length; index++) {
const lowerLetter = lowerWord[index];
if (lowerVowels.includes(lowerLetter)) {
count++;
}

}
return count;
}



console.log(vowelCounter('cool sEntEncE'));
/*
let myArray = ['H', 'E', 'L', 'L', 'O'];
let myString = 'HELLO';
let myNumber = 12345;
console.log(myArray[1]);
console.log(myString[1]);
console.log(myNumber[1]); // this should error out because numbers don't have index accessors.
*/
/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
function foo(){
function foo() {
console.log('its working');
return 'bar';
}
/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Don't touch the code after this line! 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
export default{
export default {
foo,
multiply,
dogYears,
Expand All @@ -237,4 +322,4 @@ export default{
feet,
annoyingSong,
grade
}
}