From a36a835065db09a5705d0cd2a1b9244eb76878b1 Mon Sep 17 00:00:00 2001 From: Chervix <122894453+SilentSchnitzel@users.noreply.github.com> Date: Mon, 20 Mar 2023 22:45:23 -0400 Subject: [PATCH] completed some more exercises --- .../exercise_02/countries.js | 9 ++++- .../exercise_02/main.js | 38 ++++++++++++++++++- .../exercise_02/webtechs.js | 22 ++++++----- 01_Day_JavaScript_Refresher/index.html | 2 +- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/01_Day_JavaScript_Refresher/exercise_02/countries.js b/01_Day_JavaScript_Refresher/exercise_02/countries.js index 435e9d2..b348509 100644 --- a/01_Day_JavaScript_Refresher/exercise_02/countries.js +++ b/01_Day_JavaScript_Refresher/exercise_02/countries.js @@ -1,4 +1,7 @@ -const countries = [ + +export function country() +{ + const countries = [ 'Albania', 'Bolivia', 'Canada', @@ -10,4 +13,6 @@ const countries = [ 'Ireland', 'Japan', 'Kenya', - ] \ No newline at end of file +] + return countries +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/exercise_02/main.js b/01_Day_JavaScript_Refresher/exercise_02/main.js index e6885a6..a47720e 100644 --- a/01_Day_JavaScript_Refresher/exercise_02/main.js +++ b/01_Day_JavaScript_Refresher/exercise_02/main.js @@ -1,10 +1,11 @@ +import { web_tech } from "./webtechs" let text = 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' let new_array = [] let new_element = "" for(let x in text) { - if(text[x] == " ") + if(text[x] == " " || text[x] == ".") { new_array.push(new_element) new_element = "" @@ -13,4 +14,37 @@ for(let x in text) } } console.log(new_array.length) -console.log(new_array) \ No newline at end of file +console.log(new_array) //2 +let shopping_cart = ["Milk", "Coffee", "Tea", "Honey"] +if(shopping_cart[0] != "Meat") +{ + shopping_cart.splice(0, 0, "Meat") +} +if(shopping_cart[shopping_cart.length - 1] != "sugar") +{ + shopping_cart.splice(shopping_cart.length - 1, 0, "Sugar") +} +let like_honey = false +if(like_honey == false) +{ + shopping_cart.splice(shopping_cart.length - 1, 1) +} +shopping_cart[3] = "Green Tea" +console.log(shopping_cart) //3 + +console.log("untested") +let found = false +for(let i in countries) +{ + + if(countries[i] == "Ethiopia") + { + console.log("ETHIOPIA") + found = true + } +} +if(found == false) +{ + countries.push("Ethiopia") +} +console.log(countries) //4 diff --git a/01_Day_JavaScript_Refresher/exercise_02/webtechs.js b/01_Day_JavaScript_Refresher/exercise_02/webtechs.js index f46664f..b1673f3 100644 --- a/01_Day_JavaScript_Refresher/exercise_02/webtechs.js +++ b/01_Day_JavaScript_Refresher/exercise_02/webtechs.js @@ -1,9 +1,13 @@ -const webTechs = [ - 'HTML', - 'CSS', - 'JavaScript', - 'React', - 'Redux', - 'Node', - 'MongoDB', -] \ No newline at end of file +export function web_tech() +{ + const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] + return webTechs +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/index.html b/01_Day_JavaScript_Refresher/index.html index 2f361ed..ac02fe4 100644 --- a/01_Day_JavaScript_Refresher/index.html +++ b/01_Day_JavaScript_Refresher/index.html @@ -5,6 +5,6 @@
I am new to javascript. I hope this works - +