From 39fb8a037a80aaecd8a4a47a7dd4991a673bc0ff Mon Sep 17 00:00:00 2001 From: Frank Ojwang Date: Wed, 30 Apr 2025 01:25:15 +0300 Subject: [PATCH] Level 2: Completed level 2 --- .../scripts/{main.js => main.mjs} | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) rename 05_Day_Arrays/05_day_starter/scripts/{main.js => main.mjs} (67%) diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.mjs similarity index 67% rename from 05_Day_Arrays/05_day_starter/scripts/main.js rename to 05_Day_Arrays/05_day_starter/scripts/main.mjs index 936dc33..abb88ba 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.mjs @@ -1,6 +1,6 @@ // import { webTechs } from "../data/webtechs"; -// import { countries } from "../data/countries.mjs"; -// import { webTechs } from "../data/webtechs.mjs"; +import { countries } from "../data/countries.mjs"; +import { webTechs } from "../data/webtechs.mjs"; //Declare an empty array; const emptyArray = []; @@ -131,5 +131,49 @@ let text = "I love teaching and empowering people. I teach HTML, CSS, JS, React, Python."; let words = text.replace(/\,|\./gm, "").split(" "); -console.log("Text Array:", words) -console.log(`Text Length: ${words.length}`); +// console.log("Text Array:", words) +// console.log(`Text Length: ${words.length}`); + +//In the following shopping cart add, remove, edit items +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']; + +//Add 'Meat' in the beginning of your shoppinh cart if it has not been already added +let foodToAdd = "Meat"; +let checkFood = shoppingCart.includes(foodToAdd); +!checkFood ? shoppingCart.unshift(foodToAdd) : ''; +console.log(shoppingCart); + +//Add Sugar at the end of your shopping cart if it has not already been added +let foodToAdd2 = "Sugar"; +let checkFood2 = shoppingCart.includes(foodToAdd2); +!checkFood2 ? shoppingCart.push(foodToAdd2) : ""; +console.log(shoppingCart); + +//Remove Honey if you are allergic to honey +let foodToRemove = "Honey" +let allergy = shoppingCart.includes(foodToRemove); +allergy ? shoppingCart.splice(shoppingCart.indexOf(foodToRemove), 1) : null; +console.log(shoppingCart); + +//Modify Tea to 'Green Tea' +let searchItem = "Tea"; +let checkItem = shoppingCart.includes(searchItem); +checkItem ? shoppingCart[shoppingCart.indexOf(searchItem)] = "Green Tea" : null; +console.log(shoppingCart); + +//Check if Ethiopia exists in the countries array. If it exists, print 'ETHIOPIA'. If not, add it to the countries list +let checkCountries = countries.includes("Ethiopia"); +checkCountries ? console.log('ETHIOPIA') : countries.push('Ethiopia'); + +//Check if Sass exists in webTechs, if it exists, print 'Sass is a CSS Preprocessor'. If not, add Sass to webTechs + +let checkWebTechs = webTechs.includes("Sass"); +checkWebTechs ? console.log("Sass is a CSS Preprocessor") : webTechs.push("Sass"); +console.log(webTechs); + +//Concatenate the following two variables and store it in a fullStack variable +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']; +const backend = ['Node', 'Express', 'MongoDB']; + +let fullStack = frontEnd.concat(backend); +console.log(fullStack); \ No newline at end of file