From 3013a0ab723af41bec588d34d6d05c8e6ac1c037 Mon Sep 17 00:00:00 2001 From: bagaski Date: Mon, 12 Oct 2020 21:54:32 +0200 Subject: [PATCH] day 1 level 2 exercise solutions --- solutions/day-01/countries.js | 13 +++++++++++ solutions/day-01/main.js | 43 +++++++++++++++++++++++++++++++++++ solutions/day-01/webTechs.js | 9 ++++++++ 3 files changed, 65 insertions(+) create mode 100644 solutions/day-01/countries.js create mode 100644 solutions/day-01/main.js create mode 100644 solutions/day-01/webTechs.js diff --git a/solutions/day-01/countries.js b/solutions/day-01/countries.js new file mode 100644 index 0000000..1fba8f5 --- /dev/null +++ b/solutions/day-01/countries.js @@ -0,0 +1,13 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', +] diff --git a/solutions/day-01/main.js b/solutions/day-01/main.js new file mode 100644 index 0000000..db26851 --- /dev/null +++ b/solutions/day-01/main.js @@ -0,0 +1,43 @@ +//1. Create a separate countries.js file and store the countries array into this file, create a separate file web_techs.js and store the webTechs array into this file. Access both file in main.js file +import { countries } from './countries.js'; +import { webTechs } from './webTechs.js'; + +//2. First remove all the punctuations and change the string to array and count the number of words in the array +let text = + 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' + +const words = text.split(" "); + +console.log(words); +console.log(words.length); + +//3. In the following shopping cart add, remove, edit items +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'] + + //add 'Meat' in the beginning of your shopping cart if it has not been already added + shoppingCart.shift(); + shoppingCart.unshift('Meat'); + + //add Sugar at the end of you shopping cart if it has not been already added + shoppingCart.push('Sugar'); + + //remove 'Honey' if you are allergic to honey + shoppingCart.splice(3,1); + + //modify Tea to 'Green Tea' + shoppingCart[2] = 'Green Tea'; + +//4. In countries array check if 'Ethiopia' exists in the array if it exists print 'ETHIOPIA'. If it does not exist add to the countries list. +let ETH = countries.includes('Ethiopia') +ETH ? (console.log('ETHIOPIA')) : countries.push('Ethiopia') + +//5. In the webTechs array check if Sass exists in the array and if it exists print 'Sass is a CSS preprocess'. If it does not exist add Sass to the array and print the array. +webTechs.includes('Sass') ? console.log('Sass is a CSS preprocess') : webTechs.push('Sass') && console.log(webTechs); + + +//6. Concatenate the following two variables and store it in a fullStack variable. +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/webTechs.js b/solutions/day-01/webTechs.js new file mode 100644 index 0000000..093a0ec --- /dev/null +++ b/solutions/day-01/webTechs.js @@ -0,0 +1,9 @@ +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', +]