From 2f4b94b8703e744785ee8c07422b1fc5ad96d05d Mon Sep 17 00:00:00 2001 From: Firomsa Date: Tue, 5 Dec 2023 05:20:22 -0800 Subject: [PATCH] exercise level 2 complete --- solutions/day-01/level2/countries.js | 15 ++++++++ solutions/day-01/level2/main.js | 54 ++++++++++++++++++++++++++++ solutions/day-01/level2/solutions.js | 24 +++++++++++++ solutions/day-01/level2/web_techs.js | 10 ++++++ 4 files changed, 103 insertions(+) create mode 100644 solutions/day-01/level2/countries.js create mode 100644 solutions/day-01/level2/main.js create mode 100644 solutions/day-01/level2/solutions.js create mode 100644 solutions/day-01/level2/web_techs.js diff --git a/solutions/day-01/level2/countries.js b/solutions/day-01/level2/countries.js new file mode 100644 index 0000000..507c597 --- /dev/null +++ b/solutions/day-01/level2/countries.js @@ -0,0 +1,15 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', + ] + + export default countries; \ No newline at end of file diff --git a/solutions/day-01/level2/main.js b/solutions/day-01/level2/main.js new file mode 100644 index 0000000..e6e0b42 --- /dev/null +++ b/solutions/day-01/level2/main.js @@ -0,0 +1,54 @@ +// level 2 solutions +//Q1 +import countries from "./countries"; +import webTechs from "./web_techs"; + + +//Q2 +let text = + 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' + +const words = sentence.replace(/[^\w\s]/g,''); +const wordsArray = words.split(" "); +const wordCount = wordsArray.length; +console.log(wordsArray) +console.log(wordCount); + +//Q3 +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']; +shoppingCart.unshift("Meat"); +if(shoppingCart.indexOf("Sugar")===-1){ + shoppingCart.push("Sugar"); +} + +const honeyIndex = 3; +shoppingCart.splice(3,1); +shoppingCart[2]="Green Tea"; + +//Q4 + + +if(countries.indexOf("Ethiopia")===-1){ + countries.push("Ethiopia"); +} +else{ + console.log("ETHIOPIA"); +} + +//Q5 + +if(webTechs.indexOf("Sass")===-1){ + webTechs.push("Sass"); + console.log(webTechs); +} +else{ + console.log("Sass is CSS preprocess"); +} + +//Q6 +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'] +const backEnd = ['Node', 'Express', 'MongoDB'] +const fullStack = frontEnd.concat(backEnd); +console.log(fullStack); + + diff --git a/solutions/day-01/level2/solutions.js b/solutions/day-01/level2/solutions.js new file mode 100644 index 0000000..581c027 --- /dev/null +++ b/solutions/day-01/level2/solutions.js @@ -0,0 +1,24 @@ +//Q2 +let text = + 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' + +const words = sentence.replace(/[^\w\s]/g,''); +const wordsArray = words.split(" "); +const wordCount = wordsArray.length; +console.log(wordsArray) +console.log(wordCount); + +//Q3 +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']; +shoppingCart.unshift("Meat"); +if(shoppingCart.indexOf("Sugar")===-1){ + shoppingCart.push("Sugar"); +} + +const honeyIndex = 3; +shoppingCart.splice(3,1); +shoppingCart[2]="Green Tea"; + +//Q4 + + diff --git a/solutions/day-01/level2/web_techs.js b/solutions/day-01/level2/web_techs.js new file mode 100644 index 0000000..6ed7a0a --- /dev/null +++ b/solutions/day-01/level2/web_techs.js @@ -0,0 +1,10 @@ +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] +export default webTechs; \ No newline at end of file