From 53e1f58725733676135110b795779227a350a651 Mon Sep 17 00:00:00 2001 From: IQRA-ABDI Date: Thu, 23 Feb 2023 22:48:17 +0300 Subject: [PATCH 1/3] finally i finished my js assignment --- arrays.js | 38 ++++++++++++++++++++++++++++--- basics.js | 50 ++++++++++++++++++++++++++++++++++++++--- functions.js | 50 ++++++++++++++++++++++++++++++++++++++++- objects.js | 63 +++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 184 insertions(+), 17 deletions(-) diff --git a/arrays.js b/arrays.js index 9a5827f..d94af6f 100644 --- a/arrays.js +++ b/arrays.js @@ -80,6 +80,7 @@ let inventory = [ // Ma xasuustaan ID-ga gaariga 33 aad, ka caawi inay ogaadaan ID-ga gaariga 33aad. Waa inaa soo bandhigto sanadka gaariga, noocuu yahay (make) iyo modelka gaariga. Habkaan usoo bandhig: // console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*`); + console.log(inventory[32].car_model + "is goes here" + inventory[32].car_make + "is goes here" + inventory.car_year); @@ -87,25 +88,56 @@ let inventory = [ // The dealer needs the information on the last car in their inventory. What is the make and model of the last car in the inventory? Log the make and model into the console. // Waxay rabaan inay ogaadaan macluumaadka gaariga ugu dambeeyay. Waxaa ka mid ah inay noocuu yahay (make) iyo modelka gaariga ugu dambeeyay. - + console.log("last car_make is = " + inventory[inventory.length-1].car_make + "and car_model is " + inventory[inventory.length-1].car_model); + // ==== Challenge 3 ==== // The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console // Dadka qaabilsan xayaysiinta ayaa rabo in gawaarida loo soo bandhigo xarfaha habkey iskugu xigaan (alphabetically) si ay website-ka u galiyaan. Magacyada gawaawida oo dhan isku habee si A-Z ah kadibna console.log ku samee. +let carModel = []; +for(let i = 0; i < inventory.length; i++){ + carModel.push(inventory[i].car_model) + + carModel.sort(); + } +console.log(carModel); // ==== Challenge 4 ==== // The accounting team needs all the years from every car on the lot. Create a new array from the dealer data containing only the car years and log the result in the console. // Dadka qaabilsan xisaabinta ayaa rabo inay ogaadaan sanadyada gawaarida oo dhan. Array cusub samee, kadibna ku shub sanadyada gawaarida oo dhan kadibna console.log ku samee. - + +let carYear = []; +for(let i = 0; i < inventory.length; i++){ + carYear.push(inventory[i].car_year) + } + console.log(carYear); + + // ==== Challenge 5 ==== // The car lot manager needs to find out how many cars are older than the year 2000. Find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length. // Qofka maamulo ganacsiga ayaa rabo inuu ogaado inta gaari oo ka horeysay sanadkii 2000. Isticmaal array 'oldCars', kuna shub gawaarida ka horeysay 2000. Kadib console log ku samee. - +let oldCar = []; +for (let i = 0; i < inventory.length; i++){ + if (inventory[i].car_year > 2000 ){ + oldCar.push(inventory[i].car_year); + console.log(oldCar) + } + } + console.log(oldCar); + + // ==== Challenge 6 ==== // A buyer is interested in seeing only BMW and Audi cars within the inventory. Return an array that only contains BMW and Audi cars. Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console. // Qof rabo inuu gaari gato ayaa rabo inuu ogaado inta BMW iyo Audi yaalo. Array 'BMWAndAudi' la dhaho ku shub dhamaan gawaarida BMW iyo Audi. Kadib adigoo isticmaalaayo JSON.stringify() console.log ku samee. +let BMW_Audi = []; +for( let i =0; i < inventory.length; i++){ + if(( inventory[i].car_make ==="BMW" ) || (inventory[i].car_make ==="Audi") ){ + BMW_Audi.push(inventory[i].car_make); + } +} + console.log(BMW_Audi); \ No newline at end of file diff --git a/basics.js b/basics.js index 8036dce..258e9c6 100644 --- a/basics.js +++ b/basics.js @@ -8,6 +8,9 @@ Do the following: HINT: look up the Number method / Raadi Number Method wax la dhaho */ +let number = "1999"; +parseInt(number); +console.log(typeof (number)); /* @@ -19,7 +22,21 @@ Do the following: 3. Else just print 'So moody!' / Hadii kale 'So Moody!' soo saar. */ +let mood = prompt ('enter your mood today'); // - happy or -'sad' +let mood1='happy'; +let mood2='sad'; +if (mood==mood1){ + console.log("Yay me too!"); +} +else if(mood==mood2){ + console.log("Aw cheer up"); + +} +else{ + console.log("So moody!"); + +} /* Task: Odd or Even / kisi ama dhaban @@ -31,6 +48,12 @@ Adigoo 'if/else' isticmaalaayo hubi in nambar uu yahay 'kisi ama dhaban', kadi c */ var num = 16; // You can change this number! / Number-kaan ku bilow +if (num%2==1){ + console.log("this number is odd"); +} +else { + console.log("this number is even"); +} // write your conditions here / Code-kaada halkaan ku qor @@ -38,6 +61,7 @@ var num = 16; // You can change this number! / Number-kaan ku bilow + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task: FIZZBUZZ 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ /* @@ -92,6 +116,15 @@ It's okay for it to be slow. */ +for (let A = 1; A < 101; A++) { + if (A % 3 == 0) + console.log("Fizz"); + else if (A % 5 == 0) + console.log("Buzz"); + else if (A % 15 == 0) + console.log("FizzBuzz"); + else console.log("the number is prime"); +} /*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/ @@ -107,6 +140,17 @@ Using the vowelCounter function below do the following: */ -function vowelCounter(/*add your code here*/) { - /*add your code here*/ -} +function vowelCounter(vowel) { + let count = 0; + let char = ["a", "e", "i", "o", "u" ]; + + for (let i = 0; i < vowel.length; i++) { + let change = vowel[i].toLowerCase(); + if (char.includes(change)) { + count++; + } + } + + return count; + } + console.log(vowelCounter("Hello Iqra!")); diff --git a/functions.js b/functions.js index e88aca4..eb1f866 100644 --- a/functions.js +++ b/functions.js @@ -28,6 +28,24 @@ let add = function (param1, param2) { add(1,2); */ +let myFunction = () => { + console.log("Function was invoked!"); + }; + + myFunction(); + + let anotherFunction = (param) => { + return param; + }; + + anotherFunction("Example"); + + + let add = (param1, param2) => { + return param1 + param2; + }; + + add(1,2); @@ -51,4 +69,34 @@ Use the game function below to do the following: function game(user, computer){ /*add your code here*/ -} + if (user === "rock") { + if (computer === "rock") { + return "it's a tie"; + } else if (computer === "paper") { + return "you lose!"; + } else { + return "you win!"; + } + } else if (user === "paper") { + if (computer === "rock") { + return "you win!"; + } else if (computer === "paper") { + return "it's a tie"; + } else { + return "you lose!"; + } + } else { + if (computer === "rock") { + return "you lose!"; + } else if (computer === "paper") { + return "you win!"; + } else { + return "it's a tie"; + } + } + } + + let result = game("rock", "paper"); + + console.log(result); + diff --git a/objects.js b/objects.js index 9640e8c..c75bfb5 100644 --- a/objects.js +++ b/objects.js @@ -18,27 +18,70 @@ const example = { } // Write your intern objects here: - + let interns = { + intern1 : { + id: 1, + Fname: "Mitzi", + email: "mmelloy0@psu.edu", + gender: "F", + }, + intern2 : { + id: 2, + Fname: "Kennan", + email: "kdiben1@tinypic.com", + gender: "m", + }, + intern3 : { + id: 3, + Fname: "Keven", + email: "kmummery2@wikimedia.org", + gender: "M", + }, + intern4 : { + id: 4, + Fname: "Gannie", + email: "gmartinson3@illinois.edu", + gender: "M", + }, + intern5 : { + id: 5, + Fname: "Antonietta", + email: "adaine5@samsung.com", + gender: "F", + } + +}; + // ==== Challenge 2: Reading Object Data ==== // Once your objects are created, log out the following requests from HR into the console: // Mitzi's name - + console.log(interns.intern1.Fname) + // Kennan's ID - + console.log(interns.intern2.id) + // Keven's email - + console.log(interns.intern3.email) + // Gannie's name - + console.log(interns.intern4.Fname) + // Antonietta's Gender - + console.log(interns.intern5.gender) + // ==== Challenge 3: Object Methods ==== // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. - // console.log(kennan.speak()); - + speak=function(){ + return `hi my name is ${this.Fname}` + } + console.log(interns.intern2.speak()); // Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint. - //console.log(antonietta.multiplyNums(3,4)); - + multiplyNums=function(a,b){ + return a/b; + + } + console.log(interns.intern5.multiplyNums(3,4)); // === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. \ No newline at end of file From c2757d5f7a7afce472a4ed3a3efe44ea8c0cc0a1 Mon Sep 17 00:00:00 2001 From: Iqra Abdifitax Hussein <98606326+IQRA-ABDI@users.noreply.github.com> Date: Thu, 23 Feb 2023 22:57:23 +0300 Subject: [PATCH 2/3] Update functions.js --- functions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.js b/functions.js index eb1f866..d3066df 100644 --- a/functions.js +++ b/functions.js @@ -28,7 +28,7 @@ let add = function (param1, param2) { add(1,2); */ -let myFunction = () => { +const myFunction = () => { console.log("Function was invoked!"); }; @@ -41,7 +41,7 @@ let myFunction = () => { anotherFunction("Example"); - let add = (param1, param2) => { + var add = (param1, param2) => { return param1 + param2; }; @@ -96,7 +96,7 @@ function game(user, computer){ } } - let result = game("rock", "paper"); + const result = game("rock", "paper"); console.log(result); From 3ac524ffbebbbf6d659f22819487945e2a9da9cc Mon Sep 17 00:00:00 2001 From: Iqra Abdifitax Hussein <98606326+IQRA-ABDI@users.noreply.github.com> Date: Thu, 23 Feb 2023 22:58:06 +0300 Subject: [PATCH 3/3] i updated my function task --- functions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/functions.js b/functions.js index d3066df..9a4ad56 100644 --- a/functions.js +++ b/functions.js @@ -99,4 +99,3 @@ function game(user, computer){ const result = game("rock", "paper"); console.log(result); -