From 9c28dc62bb4714c4f4d90eda7ff663c5c0503d67 Mon Sep 17 00:00:00 2001 From: zayid Date: Tue, 15 Nov 2022 16:21:17 +0600 Subject: [PATCH] solving the js-fundamental exercise 2 --- exercise.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/exercise.js b/exercise.js index da0af63..bd87d59 100644 --- a/exercise.js +++ b/exercise.js @@ -1,2 +1,56 @@ // Good Luck! You got this 💪🏾 // Write your code here. + + +// Functions + +function describeCountry(country,population ,capitalCity){ + console.log(country +' has '+population + ' million people and its captial city is '+ capitalCity ); +} +describeCountry('somalind','3.5','Hargeisa'); +describeCountry('Bangladesh','168','Dhaka'); +describeCountry('Turkey','86','Ankara'); + +function percentageOfWorld1(country ,population){ + let pop_percentage= (population / 7900) *100 ; +console.log( country+" has "+ population+ " million people, so it's about " + pop_percentage + " of the world population"); +} +const som_world_pop = percentageOfWorld1("Somalia",16); +const turkey_world_pop = percentageOfWorld1("Turkey",86); +const china_world_pop = percentageOfWorld1("China",1441); + + +// Introduction to arrays + + let population = [86000000,168000000 ,16000000]; + let neighbours =[ "kenya","Djibouti" ,"Ethiopia"] + + if(neighbours.length ==4){ + console.log(true) + }else{ + console.log(false) + } + + //Iteration: for loops + + for(let i=0;i<=2;i++){ + console.log(neighbours[i]) + } + + for(let i=2 ;i>=0 ;i--){ + console.log(neighbours[i]) + } + + //Iteration: while loop + + let i = 0 + while(i<2){ + console.log(neighbours[i]) + i++ +} + +let j = 3 +while(j>=0){ + console.log(neighbours[j]) + j-- +}