From 9a9e21c9833e7b6ae83a068b23aca596185f9e17 Mon Sep 17 00:00:00 2001 From: BluKnight98 <70171431+BluKnight98@users.noreply.github.com> Date: Tue, 6 Oct 2020 10:56:15 -0700 Subject: [PATCH 1/4] first function --- index.js | 60 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index d48019306..9a360d2ce 100644 --- a/index.js +++ b/index.js @@ -58,11 +58,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 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -74,7 +74,7 @@ Do the following: 3. Return the newly calculated age */ -function dogYears(/*add your code here*/){ +function dogYears( /*add your code here*/ ) { /*add your code here*/ } @@ -105,11 +105,11 @@ 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*/){ +function hungryDog( /*add your code here*/ ) { /*add your code here*/ - } +} @@ -127,11 +127,11 @@ Use the game function below to do the following: 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*/){ +function game( /*add your code here*/ ) { /*add your code here*/ } - - + + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -144,9 +144,9 @@ Using the miles function below do the following: 3. Return the number of miles */ -function miles(/*add your code here*/){ +function miles( /*add your code here*/ ) { /*add your code here*/ - } +} @@ -158,10 +158,10 @@ Using the feet function below do the following: 3. Return number of centimeters */ -function feet(/*add your code here*/){ +function feet( /*add your code here*/ ) { /*add your code here*/ - } - +} + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -174,9 +174,9 @@ 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( /*add your code here*/ ) { + /*add your code here*/ +} /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -193,14 +193,14 @@ Using the grade function below do the following: 60-69 = D below 60 = F */ - -function grade(/*add your code here*/){ + +function grade( /*add your code here*/ ) { /*add your code here*/ - } - - - - +} + + + + /*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/ @@ -215,19 +215,19 @@ Using the vowelCounter function below do the following: */ -function vowelCounter(/*add your code here*/) { +function vowelCounter( /*add your code here*/ ) { /*add your code here*/ } /*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 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, @@ -237,4 +237,4 @@ export default{ feet, annoyingSong, grade -} +} \ No newline at end of file From d2f7ac2e96459871202ed868226347996e559525 Mon Sep 17 00:00:00 2001 From: BluKnight98 <70171431+BluKnight98@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:42:07 -0700 Subject: [PATCH 2/4] updated js --- __tests__/index.test.js | 46 ++++++------ index.js | 154 ++++++++++++++++++++++++++++++---------- 2 files changed, 138 insertions(+), 62 deletions(-) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index fff371143..4a5298f55 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -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'); }) -}); - - +}); \ No newline at end of file diff --git a/index.js b/index.js index 9a360d2ce..bbfd4ed76 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,10 @@ Do the following: HINT: no function required */ - - +const votingAge = 22; +if (votingAge >= 18) { + console.log(true); +} /* Task 1b - Values @@ -30,9 +32,12 @@ Do the following: HINT: no function required */ - - - +let variable1 = 1; +let variable2 = 2; +if (variable2 === 2) { + variable1 = 3; + console.log(variable1); +} /* @@ -45,7 +50,13 @@ Do the following: HINT: look up the Number method */ - +let stringValue = '1999'; +let numValue = parseInt(stringValue); +if (numValue === 1999) { + console.log(numValue) +} else { + console.error('Did not get expected result'); +} @@ -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 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -107,30 +118,71 @@ Use the hungryDog function and feeding requirements below to do the following: 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 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -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 /* @@ -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 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -174,10 +226,16 @@ 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 = number - 1; + //number--; + //} +} +console.log(annoyingSong(5)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -194,11 +252,21 @@ Using the grade function below do the following: 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)); @@ -213,12 +281,22 @@ 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.indexOf(lowerLetter) > -1) { + count++; + } + + } + return count; } - +console.log(vowelCounter('cool sEntEncE')); /*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ From ca11fd170102bdfe1b8977f8bc8c4e5a25a50b1f Mon Sep 17 00:00:00 2001 From: BluKnight98 <70171431+BluKnight98@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:46:42 -0700 Subject: [PATCH 3/4] Create a CodeGrade submission From f76ae7937cf6f63cf4afa9ad8b45dc2a3132a407 Mon Sep 17 00:00:00 2001 From: BluKnight98 <70171431+BluKnight98@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:22:52 -0700 Subject: [PATCH 4/4] added comments --- index.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index bbfd4ed76..092772ad2 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,8 @@ Do the following: HINT: no function required */ -const votingAge = 22; -if (votingAge >= 18) { +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); } @@ -34,7 +34,7 @@ Do the following: */ let variable1 = 1; let variable2 = 2; -if (variable2 === 2) { +if (variable2 === 2) { // since variable2 does equal 2, the new value for variable1 will be logged variable1 = 3; console.log(variable1); } @@ -51,7 +51,7 @@ Do the following: HINT: look up the Number method */ let stringValue = '1999'; -let numValue = parseInt(stringValue); +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 { @@ -228,11 +228,12 @@ Using the annoyingSong function below do the following: 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) { + /* + 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 = number - 1; - //number--; - //} + number--; // decreases number 1 + } + */ } console.log(annoyingSong(5)); @@ -289,7 +290,7 @@ function vowelCounter(word) { let count = 0; for (let index = 0; index < lowerWord.length; index++) { const lowerLetter = lowerWord[index]; - if (lowerVowels.indexOf(lowerLetter) > -1) { + if (lowerVowels.includes(lowerLetter)) { count++; } @@ -297,8 +298,14 @@ function vowelCounter(word) { 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() { console.log('its working');