From 2c957bc1fc9eb3b600c621eaba52d916833c0c87 Mon Sep 17 00:00:00 2001 From: hamda Date: Mon, 14 Nov 2022 19:58:31 +0000 Subject: [PATCH] finished Js-fundamentals-exercises-2 --- exercise.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/exercise.js b/exercise.js index da0af63..7edd99c 100644 --- a/exercise.js +++ b/exercise.js @@ -1,2 +1,54 @@ // Good Luck! You got this 💪🏾 // Write your code here. + +//Functions + +let describeCountry = (country,population,capitalCity) =>{ + return console.log(`${country} has ${population} million people and its captial city is ${capitalCity}`) +} + +let country1 = describeCountry("Somaliland",3.5,"Hargeisa"); +let country2 = describeCountry("Switzerland",8.6,"Bern"); +let country3 = describeCountry("Canada",38,"Ottawa"); + + +let percentageOfWorld1 = (population) =>{ + percentage = (population/7900)*100; + return percentage; + +} + +let Indians = console.log(Math.floor(percentageOfWorld1(1393))); +let Somalis = console.log(Math.ceil(percentageOfWorld1(17))); +let Mexicans = console.log(Math.ceil(percentageOfWorld1(125))); + +//Introduction to arrays + +let population = [500000,2000000,7500,88000]; +let neighbors = ["Kenya","Djibouti","Ethiopia","Somalia"]; +console.log(neighbors.length === 4); + +//Iteration: for loops + +for(let i=0; i=0; i--){ + console.log(neighbors[i]); +} +//Iteration: while loop +let i=0; +while (i=0){ + console.log(neighbors[i]); + i--; +} + + +