From 87ea88c679f3f03f8ce3886ec4a85d5f0e679ea9 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 6 Jun 2025 15:28:39 +0000 Subject: [PATCH 1/2] First attempt JavaSccript --- .learn/resets/01-Hello_World/app.js | 1 + .../02-Print_variables_in_the_console/app.js | 4 ++ .learn/resets/03-Multiply_two_values/app.js | 1 + .../resets/04-User_inputed_variables/app.js | 3 ++ .learn/resets/05-Constants/app.js | 5 +++ .learn/resets/06-String_concatenation/app.js | 7 ++++ .learn/resets/07-Create_a_basic_HTML/app.js | 13 +++++++ .../08-Calling_your_first_function/app.js | 7 ++++ .../09-Creating_your_first_function/app.js | 7 ++++ .learn/resets/10-Create_a_new_function/app.js | 7 ++++ .learn/resets/11-Your_first_if/app.js | 3 ++ .../12-How_much_the_wedding_costs/app.js | 12 ++++++ .learn/resets/13-Your_first_switch/app.js | 17 +++++++++ .learn/resets/14-Random_numbers/app.js | 8 ++++ .learn/resets/15-Rand_from_one_to_six/app.js | 6 +++ .learn/resets/16-Your_first_loop/app.js | 3 ++ .learn/resets/17-Create_a_for_loop/app.js | 4 ++ .learn/resets/18-While_loop/app.js | 12 ++++++ .learn/resets/19-Random_colors_loop/app.js | 26 +++++++++++++ .learn/resets/20-Looping_with_FizzBuzz/app.js | 5 +++ .learn/resets/21-Russian_Roulette/app.js | 18 +++++++++ .learn/resets/22-The_Beatles/app.js | 5 +++ .learn/resets/23-Bottles_of_milk/app.js | 1 + .learn/resets/24-Javascript_Objects/app.js | 38 +++++++++++++++++++ exercises/01-Hello_World/app.js | 2 + .../02-Print_variables_in_the_console/app.js | 2 + exercises/03-Multiply_two_values/app.js | 4 +- exercises/04-User_inputed_variables/app.js | 1 + exercises/05-Constants/app.js | 2 +- exercises/06-String_concatenation/app.js | 4 +- exercises/07-Create_a_basic_HTML/app.js | 2 +- .../08-Calling_your_first_function/app.js | 2 +- .../09-Creating_your_first_function/app.js | 4 +- exercises/10-Create_a_new_function/app.js | 9 +++-- .../10-Create_a_new_function/solution.hide.js | 4 +- exercises/11-Your_first_if/app.js | 10 +++++ .../12-How_much_the_wedding_costs/app.js | 21 +++++++++- .../12-How_much_the_wedding_costs/tests.js | 18 ++++----- exercises/13-Your_first_switch/app.js | 4 ++ exercises/13-Your_first_switch/tests.js | 2 +- exercises/14-Random_numbers/app.js | 3 +- exercises/15-Rand_from_one_to_six/app.js | 3 +- exercises/16-Your_first_loop/app.js | 2 +- exercises/17-Create_a_for_loop/app.js | 8 ++-- exercises/18-While_loop/app.js | 5 ++- exercises/19-Random_colors_loop/app.js | 9 ++++- exercises/20-Looping_with_FizzBuzz/app.js | 12 ++++++ exercises/21-Russian_Roulette/app.js | 2 + exercises/22-The_Beatles/app.js | 10 ++++- exercises/23-Bottles_of_milk/app.js | 16 ++++++++ exercises/24-Javascript_Objects/app.js | 27 +++++++++---- 51 files changed, 361 insertions(+), 40 deletions(-) create mode 100644 .learn/resets/01-Hello_World/app.js create mode 100644 .learn/resets/02-Print_variables_in_the_console/app.js create mode 100644 .learn/resets/03-Multiply_two_values/app.js create mode 100644 .learn/resets/04-User_inputed_variables/app.js create mode 100644 .learn/resets/05-Constants/app.js create mode 100644 .learn/resets/06-String_concatenation/app.js create mode 100644 .learn/resets/07-Create_a_basic_HTML/app.js create mode 100644 .learn/resets/08-Calling_your_first_function/app.js create mode 100644 .learn/resets/09-Creating_your_first_function/app.js create mode 100644 .learn/resets/10-Create_a_new_function/app.js create mode 100644 .learn/resets/11-Your_first_if/app.js create mode 100644 .learn/resets/12-How_much_the_wedding_costs/app.js create mode 100644 .learn/resets/13-Your_first_switch/app.js create mode 100644 .learn/resets/14-Random_numbers/app.js create mode 100644 .learn/resets/15-Rand_from_one_to_six/app.js create mode 100644 .learn/resets/16-Your_first_loop/app.js create mode 100644 .learn/resets/17-Create_a_for_loop/app.js create mode 100644 .learn/resets/18-While_loop/app.js create mode 100644 .learn/resets/19-Random_colors_loop/app.js create mode 100644 .learn/resets/20-Looping_with_FizzBuzz/app.js create mode 100644 .learn/resets/21-Russian_Roulette/app.js create mode 100644 .learn/resets/22-The_Beatles/app.js create mode 100644 .learn/resets/23-Bottles_of_milk/app.js create mode 100644 .learn/resets/24-Javascript_Objects/app.js diff --git a/.learn/resets/01-Hello_World/app.js b/.learn/resets/01-Hello_World/app.js new file mode 100644 index 00000000..2290d4e6 --- /dev/null +++ b/.learn/resets/01-Hello_World/app.js @@ -0,0 +1 @@ +//your code below diff --git a/.learn/resets/02-Print_variables_in_the_console/app.js b/.learn/resets/02-Print_variables_in_the_console/app.js new file mode 100644 index 00000000..4d6f4093 --- /dev/null +++ b/.learn/resets/02-Print_variables_in_the_console/app.js @@ -0,0 +1,4 @@ +let mySuperVariable = 'hello'; +console.log(mySuperVariable); + +// your code below diff --git a/.learn/resets/03-Multiply_two_values/app.js b/.learn/resets/03-Multiply_two_values/app.js new file mode 100644 index 00000000..de14e4e5 --- /dev/null +++ b/.learn/resets/03-Multiply_two_values/app.js @@ -0,0 +1 @@ +// Your code below: \ No newline at end of file diff --git a/.learn/resets/04-User_inputed_variables/app.js b/.learn/resets/04-User_inputed_variables/app.js new file mode 100644 index 00000000..64e98ae0 --- /dev/null +++ b/.learn/resets/04-User_inputed_variables/app.js @@ -0,0 +1,3 @@ +let age = prompt('What is your age?'); + +// Your code below: diff --git a/.learn/resets/05-Constants/app.js b/.learn/resets/05-Constants/app.js new file mode 100644 index 00000000..407c5085 --- /dev/null +++ b/.learn/resets/05-Constants/app.js @@ -0,0 +1,5 @@ +const VERSION = '0.1'; + +VERSION = '0.9'; + +console.log(VERSION); \ No newline at end of file diff --git a/.learn/resets/06-String_concatenation/app.js b/.learn/resets/06-String_concatenation/app.js new file mode 100644 index 00000000..7913ca21 --- /dev/null +++ b/.learn/resets/06-String_concatenation/app.js @@ -0,0 +1,7 @@ +//Set the values here +let myVar1 = ''; +let myVar2 = ''; + +//Don't change any code below +let theNewString = myVar1+' '+myVar2; +console.log(theNewString); \ No newline at end of file diff --git a/.learn/resets/07-Create_a_basic_HTML/app.js b/.learn/resets/07-Create_a_basic_HTML/app.js new file mode 100644 index 00000000..901e8f77 --- /dev/null +++ b/.learn/resets/07-Create_a_basic_HTML/app.js @@ -0,0 +1,13 @@ +const a = ''; +const b = ''; +const c = ''; +const d = ''; +const e = ''; +const f = ''; +const g = ''; +const h = '<body>'; + +//Modify this variable +let htmlDocument = 'e+c+g+h+d+a+f+b'; + +console.log(htmlDocument); \ No newline at end of file diff --git a/.learn/resets/08-Calling_your_first_function/app.js b/.learn/resets/08-Calling_your_first_function/app.js new file mode 100644 index 00000000..0fa5a6e9 --- /dev/null +++ b/.learn/resets/08-Calling_your_first_function/app.js @@ -0,0 +1,7 @@ +function isOdd(myNumber) +{ + return !(myNumber % 2 == 0); +} + +// Your code below: +isOdd() \ No newline at end of file diff --git a/.learn/resets/09-Creating_your_first_function/app.js b/.learn/resets/09-Creating_your_first_function/app.js new file mode 100644 index 00000000..feb681a4 --- /dev/null +++ b/.learn/resets/09-Creating_your_first_function/app.js @@ -0,0 +1,7 @@ +function addNumbers(a,b){ + // This is the function's body. Write your code here. + +} + +//Do not change the code below +console.log(addNumbers(3,4)); diff --git a/.learn/resets/10-Create_a_new_function/app.js b/.learn/resets/10-Create_a_new_function/app.js new file mode 100644 index 00000000..1aebdb53 --- /dev/null +++ b/.learn/resets/10-Create_a_new_function/app.js @@ -0,0 +1,7 @@ +function shortIntroduction() { + // Complete this function's body and arguments + +} + +// Fill the gaps with your data in the correct order +console.log(shortIntroduction(" ", " ", " ")) \ No newline at end of file diff --git a/.learn/resets/11-Your_first_if/app.js b/.learn/resets/11-Your_first_if/app.js new file mode 100644 index 00000000..217b619e --- /dev/null +++ b/.learn/resets/11-Your_first_if/app.js @@ -0,0 +1,3 @@ +let total = prompt('How many km are left to go?'); + +// Your code below: diff --git a/.learn/resets/12-How_much_the_wedding_costs/app.js b/.learn/resets/12-How_much_the_wedding_costs/app.js new file mode 100644 index 00000000..d769ef63 --- /dev/null +++ b/.learn/resets/12-How_much_the_wedding_costs/app.js @@ -0,0 +1,12 @@ +let guests = prompt('How many people are coming to your wedding?'); + +function getPrice(guests){ + let cost = 0; + // Your code here + + + return cost; +} + +let price = getPrice(guests); +console.log('Your wedding will cost '+price+' dollars'); diff --git a/.learn/resets/13-Your_first_switch/app.js b/.learn/resets/13-Your_first_switch/app.js new file mode 100644 index 00000000..2bc6601b --- /dev/null +++ b/.learn/resets/13-Your_first_switch/app.js @@ -0,0 +1,17 @@ +function getColor(selection) +{ + switch(selection){ + // Add more options here + default: + return false; //returns false because the user picked an unavailable color + break; + } +} + +let colorname = prompt('What color do you want?').trim(); +let isAvailable = getColor(colorname); + +if(isAvailable) + console.log('Good news! That color is available'); +else + console.log('We are sorry, that color is not available'); diff --git a/.learn/resets/14-Random_numbers/app.js b/.learn/resets/14-Random_numbers/app.js new file mode 100644 index 00000000..73ab6d92 --- /dev/null +++ b/.learn/resets/14-Random_numbers/app.js @@ -0,0 +1,8 @@ +function getRandomInt() +{ + let randomNumber = Math.random(); + return randomNumber; +} + + +console.log(getRandomInt()); diff --git a/.learn/resets/15-Rand_from_one_to_six/app.js b/.learn/resets/15-Rand_from_one_to_six/app.js new file mode 100644 index 00000000..a5f2d3a6 --- /dev/null +++ b/.learn/resets/15-Rand_from_one_to_six/app.js @@ -0,0 +1,6 @@ +function getRandomInt() +{ + let randomNumber = Math.random(); + return randomNumber; +} +console.log(getRandomInt()); \ No newline at end of file diff --git a/.learn/resets/16-Your_first_loop/app.js b/.learn/resets/16-Your_first_loop/app.js new file mode 100644 index 00000000..96256cf1 --- /dev/null +++ b/.learn/resets/16-Your_first_loop/app.js @@ -0,0 +1,3 @@ +for (let i = 0; i < 100; i++) { + console.log(i) +} diff --git a/.learn/resets/17-Create_a_for_loop/app.js b/.learn/resets/17-Create_a_for_loop/app.js new file mode 100644 index 00000000..523830fd --- /dev/null +++ b/.learn/resets/17-Create_a_for_loop/app.js @@ -0,0 +1,4 @@ +// Declare and write your function here: + + +standardsMaker(); \ No newline at end of file diff --git a/.learn/resets/18-While_loop/app.js b/.learn/resets/18-While_loop/app.js new file mode 100644 index 00000000..01fd584b --- /dev/null +++ b/.learn/resets/18-While_loop/app.js @@ -0,0 +1,12 @@ +//fix this function: +function startCounting() { + let counter = 100; + while (counter <= 100) { + counter--; + console.log(counter); + } + + return counter; +} + +startCounting(); \ No newline at end of file diff --git a/.learn/resets/19-Random_colors_loop/app.js b/.learn/resets/19-Random_colors_loop/app.js new file mode 100644 index 00000000..f5113a15 --- /dev/null +++ b/.learn/resets/19-Random_colors_loop/app.js @@ -0,0 +1,26 @@ +function getColor(colorNumber = 0) { + //make sure the parameter is a number and not a string by converting the value to int: + colorNumber = parseInt(colorNumber); + switch (colorNumber) { + case 1: return "red"; + + case 2: return "yellow"; + + case 3: return "blue"; + + case 4: return "green"; + + default: return "black"; + + } +} + +function getAllStudentColors() { + + //your loop here + let exampleColor = getColor(1); +} + +//call the function below with the number of students in the class and print on the console +getAllStudentColors(); + diff --git a/.learn/resets/20-Looping_with_FizzBuzz/app.js b/.learn/resets/20-Looping_with_FizzBuzz/app.js new file mode 100644 index 00000000..2870ef1e --- /dev/null +++ b/.learn/resets/20-Looping_with_FizzBuzz/app.js @@ -0,0 +1,5 @@ +function fizzBuzz() { + // Your code here +} + +fizzBuzz(); \ No newline at end of file diff --git a/.learn/resets/21-Russian_Roulette/app.js b/.learn/resets/21-Russian_Roulette/app.js new file mode 100644 index 00000000..f6def2af --- /dev/null +++ b/.learn/resets/21-Russian_Roulette/app.js @@ -0,0 +1,18 @@ +// firePosition will be the position in which the gun will fire. +let firePosition = 1; + +// The output of spinChamber will be a number and it can be passed as a parameter to the fireGun function. +const spinChamber = () => { + let chamberPosition = Math.floor((Math.random() * 6) + 1); + return chamberPosition; +}; + +// Remove the // below and complete the commented lines +const fireGun = (bulletPosition) => { + // if (... === firePosition) return ("You're dead!"); + // else return ("Keep playing!"); + if (bulletPosition === firePosition) return ("You're dead!"); + else return ("Keep playing!"); +}; + +console.log(fireGun(spinChamber())); diff --git a/.learn/resets/22-The_Beatles/app.js b/.learn/resets/22-The_Beatles/app.js new file mode 100644 index 00000000..1111c793 --- /dev/null +++ b/.learn/resets/22-The_Beatles/app.js @@ -0,0 +1,5 @@ + + +//Your code above ^^^ + +console.log(sing()); \ No newline at end of file diff --git a/.learn/resets/23-Bottles_of_milk/app.js b/.learn/resets/23-Bottles_of_milk/app.js new file mode 100644 index 00000000..f37016c1 --- /dev/null +++ b/.learn/resets/23-Bottles_of_milk/app.js @@ -0,0 +1 @@ +// Your code here: diff --git a/.learn/resets/24-Javascript_Objects/app.js b/.learn/resets/24-Javascript_Objects/app.js new file mode 100644 index 00000000..fa1e623a --- /dev/null +++ b/.learn/resets/24-Javascript_Objects/app.js @@ -0,0 +1,38 @@ +var person = { + name: "John", //String + lastName: "Doe", + age: 35, //Number + gender: "male", + luckyNumbers: [7, 11, 13, 17], //Array + significantOther: person2 //Object, yes, the same variable/object defined after +}; + +var person2 = { + name: "Jane", + lastName: "Doe", + age: 38, + gender: "female", + luckyNumbers: [2, 4, 6, 8], + significantOther: person +}; + +var family = { + lastName: "Doe", + members: [person, person2] //Array of objects, don't forget to add Jimmy +}; + + +function addAllFamilyLuckyNumbers(anArray){ + let sumOfAllLuckyNumbers = 0; //sumOfAllLuckyNumbers is a number, the sum of all lucky numbers. + + //To-Do: loop and add; consider nested loops + //Hint: use the anArray variable to get all of the lucky numbers + + return sumOfAllLuckyNumbers; +} + +//Enter all your code here: + + +//Do not make changes below: +console.log(addAllFamilyLuckyNumbers(family.members)); diff --git a/exercises/01-Hello_World/app.js b/exercises/01-Hello_World/app.js index 2290d4e6..628acc5c 100644 --- a/exercises/01-Hello_World/app.js +++ b/exercises/01-Hello_World/app.js @@ -1 +1,3 @@ //your code below +console.log("Hello World"); + diff --git a/exercises/02-Print_variables_in_the_console/app.js b/exercises/02-Print_variables_in_the_console/app.js index 4d6f4093..218d3ead 100644 --- a/exercises/02-Print_variables_in_the_console/app.js +++ b/exercises/02-Print_variables_in_the_console/app.js @@ -2,3 +2,5 @@ let mySuperVariable = 'hello'; console.log(mySuperVariable); // your code below +let color = "red" +console.log(color); \ No newline at end of file diff --git a/exercises/03-Multiply_two_values/app.js b/exercises/03-Multiply_two_values/app.js index de14e4e5..2a5913bd 100644 --- a/exercises/03-Multiply_two_values/app.js +++ b/exercises/03-Multiply_two_values/app.js @@ -1 +1,3 @@ -// Your code below: \ No newline at end of file +// Your code below: +let variablesAreCool = 2345 * 7323; +console.log(variablesAreCool); \ No newline at end of file diff --git a/exercises/04-User_inputed_variables/app.js b/exercises/04-User_inputed_variables/app.js index 64e98ae0..f9aa847a 100644 --- a/exercises/04-User_inputed_variables/app.js +++ b/exercises/04-User_inputed_variables/app.js @@ -1,3 +1,4 @@ let age = prompt('What is your age?'); // Your code below: +console.log(parseInt(age) + 10); \ No newline at end of file diff --git a/exercises/05-Constants/app.js b/exercises/05-Constants/app.js index 407c5085..e7b6c77e 100644 --- a/exercises/05-Constants/app.js +++ b/exercises/05-Constants/app.js @@ -1,4 +1,4 @@ -const VERSION = '0.1'; +let VERSION = '0.1'; VERSION = '0.9'; diff --git a/exercises/06-String_concatenation/app.js b/exercises/06-String_concatenation/app.js index 7913ca21..80dd9155 100644 --- a/exercises/06-String_concatenation/app.js +++ b/exercises/06-String_concatenation/app.js @@ -1,6 +1,6 @@ //Set the values here -let myVar1 = ''; -let myVar2 = ''; +let myVar1 = 'Hello'; +let myVar2 = 'World'; //Don't change any code below let theNewString = myVar1+' '+myVar2; diff --git a/exercises/07-Create_a_basic_HTML/app.js b/exercises/07-Create_a_basic_HTML/app.js index 901e8f77..52259f78 100644 --- a/exercises/07-Create_a_basic_HTML/app.js +++ b/exercises/07-Create_a_basic_HTML/app.js @@ -8,6 +8,6 @@ const g = '<title>'; const h = '<body>'; //Modify this variable -let htmlDocument = 'e+c+g+h+d+a+f+b'; +let htmlDocument = e+c+g+a+f+h+d+b; console.log(htmlDocument); \ No newline at end of file diff --git a/exercises/08-Calling_your_first_function/app.js b/exercises/08-Calling_your_first_function/app.js index 0fa5a6e9..eba2ad39 100644 --- a/exercises/08-Calling_your_first_function/app.js +++ b/exercises/08-Calling_your_first_function/app.js @@ -4,4 +4,4 @@ function isOdd(myNumber) } // Your code below: -isOdd() \ No newline at end of file +console.log(isOdd(45345)); \ No newline at end of file diff --git a/exercises/09-Creating_your_first_function/app.js b/exercises/09-Creating_your_first_function/app.js index feb681a4..ece4eb8b 100644 --- a/exercises/09-Creating_your_first_function/app.js +++ b/exercises/09-Creating_your_first_function/app.js @@ -1,6 +1,8 @@ function addNumbers(a,b){ // This is the function's body. Write your code here. - + return a + b; + sum = a + b; + // The function returns the sum of a and b. } //Do not change the code below diff --git a/exercises/10-Create_a_new_function/app.js b/exercises/10-Create_a_new_function/app.js index 1aebdb53..f2709b27 100644 --- a/exercises/10-Create_a_new_function/app.js +++ b/exercises/10-Create_a_new_function/app.js @@ -1,7 +1,10 @@ -function shortIntroduction() { +function shortIntroduction(name, profession, age) { // Complete this function's body and arguments - + const introduction = `Hello! my name is {name}, my profession is {profession}. I am {age} years old.`; + return introduction.replace("{name}", name) + .replace("{profession}", profession) + .replace("{age}", age); } // Fill the gaps with your data in the correct order -console.log(shortIntroduction(" ", " ", " ")) \ No newline at end of file +console.log(shortIntroduction("Brian ", "Grounder ", "30 ")) \ No newline at end of file diff --git a/exercises/10-Create_a_new_function/solution.hide.js b/exercises/10-Create_a_new_function/solution.hide.js index 51acef72..f8fb16b4 100644 --- a/exercises/10-Create_a_new_function/solution.hide.js +++ b/exercises/10-Create_a_new_function/solution.hide.js @@ -1,6 +1,8 @@ function shortIntroduction(name, profession, age) { // Complete this function's body and arguments - return "Hello! my name is " + name + ", my profession is " + profession + ". I am " + age + " years old." + const introduction = 'Hello! my name is {name}, my profession is {profession}. I am {age} years old.'; + return introduction; + } // Fill the gaps with your data in the correct order diff --git a/exercises/11-Your_first_if/app.js b/exercises/11-Your_first_if/app.js index 217b619e..7207e24e 100644 --- a/exercises/11-Your_first_if/app.js +++ b/exercises/11-Your_first_if/app.js @@ -1,3 +1,13 @@ let total = prompt('How many km are left to go?'); // Your code below: +total = parseInt(total); +if ( total > 100) { + console.log("We still have a bit of driving left to go"); + } +else if (total > 50 && total <= 100) { + console.log("We'll be there in 5 minutes"); + } +else if (total <= 50) { + console.log("I'm parking. I'll see you right now"); + } \ No newline at end of file diff --git a/exercises/12-How_much_the_wedding_costs/app.js b/exercises/12-How_much_the_wedding_costs/app.js index d769ef63..e33cf7f2 100644 --- a/exercises/12-How_much_the_wedding_costs/app.js +++ b/exercises/12-How_much_the_wedding_costs/app.js @@ -3,10 +3,27 @@ let guests = prompt('How many people are coming to your wedding?'); function getPrice(guests){ let cost = 0; // Your code here - + if (guests <= 50) { + cost = 4000; + + } +else if (guests <= 100) { + cost = 10000; + + } + +else if (guests <= 200) { + cost = 15000; + + } + +else if (guests > 200) { + cost = 20000; + + } return cost; -} + } let price = getPrice(guests); console.log('Your wedding will cost '+price+' dollars'); diff --git a/exercises/12-How_much_the_wedding_costs/tests.js b/exercises/12-How_much_the_wedding_costs/tests.js index 22ec2ecb..1cdbc850 100644 --- a/exercises/12-How_much_the_wedding_costs/tests.js +++ b/exercises/12-How_much_the_wedding_costs/tests.js @@ -4,55 +4,55 @@ let fs = require('fs'); let path = require('path'); it("Create an if statement", function () { - const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); + const app_content = fs.readFileSync(path.resolve(__dirname, './temporal.js'), 'utf8'); expect(app_content).toMatch(/if\s*/); }); it('The function getPrice must exist', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice).toBeTruthy(); }); it('When tested for 50 it should return 4000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(50)).toBe(4000); }); it('When tested for 51 it should return 10000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(51)).toBe(10000); }); it('When tested for 100 it should return 10000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(100)).toBe(10000); }); it('When tested for 101 it should return 15000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(101)).toBe(15000); }); it('When tested for 200 it should return 15000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(200)).toBe(15000); }); it('When tested for 201 it should return 20000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(201)).toBe(20000); }); it('When tested for 400 it should return 20000', function () { - const app = rewire('./app.js'); + const app = rewire('./temporal.js'); const getPrice = app.__get__('getPrice') expect(getPrice(400)).toBe(20000); }); diff --git a/exercises/13-Your_first_switch/app.js b/exercises/13-Your_first_switch/app.js index 2bc6601b..12008f2d 100644 --- a/exercises/13-Your_first_switch/app.js +++ b/exercises/13-Your_first_switch/app.js @@ -2,6 +2,10 @@ function getColor(selection) { switch(selection){ // Add more options here + case 'red': + case 'blue': + case 'green': + return true; //returns true because the user picked an available color default: return false; //returns false because the user picked an unavailable color break; diff --git a/exercises/13-Your_first_switch/tests.js b/exercises/13-Your_first_switch/tests.js index deade9a0..fa02c37d 100644 --- a/exercises/13-Your_first_switch/tests.js +++ b/exercises/13-Your_first_switch/tests.js @@ -1,6 +1,6 @@ const rewire = require('rewire'); -const file = rewire("./app.js"); +const file = rewire("./temporal.js"); const getColor = file.__get__('getColor'); test('function getColor should exist', function () { expect(getColor).toBeTruthy(); diff --git a/exercises/14-Random_numbers/app.js b/exercises/14-Random_numbers/app.js index 73ab6d92..f1a1bc50 100644 --- a/exercises/14-Random_numbers/app.js +++ b/exercises/14-Random_numbers/app.js @@ -1,6 +1,7 @@ function getRandomInt() { - let randomNumber = Math.random(); + let randomNumber = Math.floor(Math.random() * 10)+1; + return randomNumber; } diff --git a/exercises/15-Rand_from_one_to_six/app.js b/exercises/15-Rand_from_one_to_six/app.js index a5f2d3a6..6c94d9da 100644 --- a/exercises/15-Rand_from_one_to_six/app.js +++ b/exercises/15-Rand_from_one_to_six/app.js @@ -1,6 +1,7 @@ function getRandomInt() { - let randomNumber = Math.random(); + let randomNumber = Math.random() * 6 + 1; // Generate a random number between 1 and 6 + randomNumber = Math.floor(randomNumber); // Round it down to the nearest integer return randomNumber; } console.log(getRandomInt()); \ No newline at end of file diff --git a/exercises/16-Your_first_loop/app.js b/exercises/16-Your_first_loop/app.js index 96256cf1..b731b45e 100644 --- a/exercises/16-Your_first_loop/app.js +++ b/exercises/16-Your_first_loop/app.js @@ -1,3 +1,3 @@ -for (let i = 0; i < 100; i++) { +for (let i = 0; i <= 100; i++) { console.log(i) } diff --git a/exercises/17-Create_a_for_loop/app.js b/exercises/17-Create_a_for_loop/app.js index 523830fd..8579bbec 100644 --- a/exercises/17-Create_a_for_loop/app.js +++ b/exercises/17-Create_a_for_loop/app.js @@ -1,4 +1,6 @@ // Declare and write your function here: - - -standardsMaker(); \ No newline at end of file +function standardsMaker() { + for (let i=0; i < 300; i++) + console.log("I will write questions if I'm stuck"); +} +standardsMaker() diff --git a/exercises/18-While_loop/app.js b/exercises/18-While_loop/app.js index 01fd584b..0b653aba 100644 --- a/exercises/18-While_loop/app.js +++ b/exercises/18-While_loop/app.js @@ -1,9 +1,10 @@ //fix this function: function startCounting() { let counter = 100; - while (counter <= 100) { - counter--; + while (counter >= 0) { console.log(counter); + counter--; + } return counter; diff --git a/exercises/19-Random_colors_loop/app.js b/exercises/19-Random_colors_loop/app.js index f5113a15..c60c0166 100644 --- a/exercises/19-Random_colors_loop/app.js +++ b/exercises/19-Random_colors_loop/app.js @@ -10,15 +10,22 @@ function getColor(colorNumber = 0) { case 4: return "green"; + + default: return "black"; + } } function getAllStudentColors() { //your loop here - let exampleColor = getColor(1); + for (let i = 0; i < 10; i++) { + //this is just to show you how to use the Math object + let exampleColor = getColor(Math.floor(Math.random() * 4) + 1); + console.log(exampleColor); + } } //call the function below with the number of students in the class and print on the console diff --git a/exercises/20-Looping_with_FizzBuzz/app.js b/exercises/20-Looping_with_FizzBuzz/app.js index 2870ef1e..97e5da3d 100644 --- a/exercises/20-Looping_with_FizzBuzz/app.js +++ b/exercises/20-Looping_with_FizzBuzz/app.js @@ -1,5 +1,17 @@ function fizzBuzz() { // Your code here + for (let i = 1; i <=100; ++i) { + if (i % 3 === 0 && i % 5 === 0) { + console.log("FizzBuzz"); + } else if (i % 3 === 0) { + console.log("Fizz"); + } else if (i % 5 === 0) { + console.log("Buzz"); + } else { + console.log(i); + } + + } } fizzBuzz(); \ No newline at end of file diff --git a/exercises/21-Russian_Roulette/app.js b/exercises/21-Russian_Roulette/app.js index b775e5ff..f6def2af 100644 --- a/exercises/21-Russian_Roulette/app.js +++ b/exercises/21-Russian_Roulette/app.js @@ -11,6 +11,8 @@ const spinChamber = () => { const fireGun = (bulletPosition) => { // if (... === firePosition) return ("You're dead!"); // else return ("Keep playing!"); + if (bulletPosition === firePosition) return ("You're dead!"); + else return ("Keep playing!"); }; console.log(fireGun(spinChamber())); diff --git a/exercises/22-The_Beatles/app.js b/exercises/22-The_Beatles/app.js index 1111c793..19c3dd76 100644 --- a/exercises/22-The_Beatles/app.js +++ b/exercises/22-The_Beatles/app.js @@ -1,4 +1,12 @@ - +function sing() { + let str =""; + for (let i = 0; i <11; i++) { + if (i === 4) str += 'there will be an answer, '; + else if (i === 10) str += 'whisper words of wisdom, let it be'; + else str += 'let it be, '; + } + return str; +} //Your code above ^^^ diff --git a/exercises/23-Bottles_of_milk/app.js b/exercises/23-Bottles_of_milk/app.js index f37016c1..e20f4944 100644 --- a/exercises/23-Bottles_of_milk/app.js +++ b/exercises/23-Bottles_of_milk/app.js @@ -1 +1,17 @@ // Your code here: +for (let i = 99; i >= 0; i--) { + if ( i === 0) { + console.log("No more bottles of milk on the wall, no more bottles of milk."); + console.log("Go to the store and buy some more, 99 bottles of milk on the wall."); + } + else if (i === 1) { + console.log("1 bottle of milk on the wall, 1 bottle of milk."); + console.log("Take it down and pass it around, no more bottles of milk on the wall."); + } + else { + console.log(i + " bottles of milk on the wall, " + i + " bottles of milk."); + console.log("Take one down and pass it around, " + (i - 1) + " bottles of milk on the wall."); + + console.log(""); // Print an empty line for better readability + } +} \ No newline at end of file diff --git a/exercises/24-Javascript_Objects/app.js b/exercises/24-Javascript_Objects/app.js index fa1e623a..48575f5a 100644 --- a/exercises/24-Javascript_Objects/app.js +++ b/exercises/24-Javascript_Objects/app.js @@ -15,24 +15,37 @@ var person2 = { luckyNumbers: [2, 4, 6, 8], significantOther: person }; +var Jimmy = { + name:'Jimmy', + lastName: 'Doe', + age: 13, + gender: 'male', + luckyNumbers: [1, 2, 3, 4], + significantOther: null + }; var family = { lastName: "Doe", - members: [person, person2] //Array of objects, don't forget to add Jimmy + members: [person, person2, Jimmy] //Array of objects, don't forget to add Jimmy }; + function addAllFamilyLuckyNumbers(anArray){ let sumOfAllLuckyNumbers = 0; //sumOfAllLuckyNumbers is a number, the sum of all lucky numbers. - + for (let i = 0; i < anArray.length; i++){ + for (let x = 0; x < anArray[i].luckyNumbers.length; x++) { + sumOfAllLuckyNumbers += anArray[i].luckyNumbers[x]; + } // Initialize the loop counter //To-Do: loop and add; consider nested loops //Hint: use the anArray variable to get all of the lucky numbers - - return sumOfAllLuckyNumbers; } - -//Enter all your code here: - +return sumOfAllLuckyNumbers; +} + + //Enter all your code here: +person.luckyNumbers[3] = 33; + // Adding Jimmy to the family members array //Do not make changes below: console.log(addAllFamilyLuckyNumbers(family.members)); From e2f0f9976981ccbb7ce8147a22dd096506fe2728 Mon Sep 17 00:00:00 2001 From: Brian <brianmarinsossa131294@gmail.com> Date: Fri, 6 Jun 2025 15:30:07 +0000 Subject: [PATCH 2/2] Initial commit