From 1688b431386dd4cd4b6fd8e96cadb2d852cd5002 Mon Sep 17 00:00:00 2001 From: Ayda Date: Mon, 7 Sep 2020 09:37:33 +0200 Subject: [PATCH 1/2] js-exercises folder created and 10 new js exercises added. --- Week1/homework/js-exercises/arrayCompare.js | 20 +++++++++++++++++ Week1/homework/js-exercises/checktype.js | 25 +++++++++++++++++++++ Week1/homework/js-exercises/errordebug.js | 4 ++++ Week1/homework/js-exercises/logNumber.js | 10 +++++++++ Week1/homework/js-exercises/logRemainder.js | 14 ++++++++++++ Week1/homework/js-exercises/logString.js | 9 ++++++++ Week1/homework/js-exercises/logarray.js | 10 +++++++++ Week1/homework/js-exercises/loghello.js | 12 ++++++++++ Week1/homework/js-exercises/loglength.js | 7 ++++++ Week1/homework/js-exercises/roundAnumber.js | 14 ++++++++++++ 10 files changed, 125 insertions(+) create mode 100644 Week1/homework/js-exercises/arrayCompare.js create mode 100644 Week1/homework/js-exercises/checktype.js create mode 100644 Week1/homework/js-exercises/errordebug.js create mode 100644 Week1/homework/js-exercises/logNumber.js create mode 100644 Week1/homework/js-exercises/logRemainder.js create mode 100644 Week1/homework/js-exercises/logString.js create mode 100644 Week1/homework/js-exercises/logarray.js create mode 100644 Week1/homework/js-exercises/loghello.js create mode 100644 Week1/homework/js-exercises/loglength.js create mode 100644 Week1/homework/js-exercises/roundAnumber.js diff --git a/Week1/homework/js-exercises/arrayCompare.js b/Week1/homework/js-exercises/arrayCompare.js new file mode 100644 index 000000000..f5d3c8700 --- /dev/null +++ b/Week1/homework/js-exercises/arrayCompare.js @@ -0,0 +1,20 @@ +'use strict'; + +// Exercise 10: Compare arrays + +//declare and initialize an array that contain my favorite foods +const myFavCities = ['Amsterdam', 'Addis Abeba', 'Paris', 'Barcelona']; +const myFavFoods = [{Italian: 'spagheti'}, 'rice', {Ethiopian: 'enjera with Dorowet'}, 'salad', 'fish', 'roasted beef', 'couscus']; +//length of the arrays +let len = myFavCities.length; +let lenFoods = myFavFoods.length; +//print out the length's of the arrays +console.log('The length of the firsta array is '+ len); +console.log('The length of the second array is '+ lenFoods); +//compare the length of the array +if (len==lenFoods){ + console.log('They are the same!'); +} +else{ + console.log('Two different sizes'); +} diff --git a/Week1/homework/js-exercises/checktype.js b/Week1/homework/js-exercises/checktype.js new file mode 100644 index 000000000..9ede0b368 --- /dev/null +++ b/Week1/homework/js-exercises/checktype.js @@ -0,0 +1,25 @@ +'use strict'; +// Exercise 8: Type checker +var x = 'love'; +var y ='patience'; +var z = {name: 'Lelida', + age: 6 + } ; +var g = { + favoriteBook: 'Prid&Prejudice', + favArtist: 'Beyonce' + +}; +function checktype(a, b){ +if (typeof a == typeof b){ + console.log('SAME TYPE') +} +else{ + console.log('Not the same ...') +} +} +checktype(x, y); +checktype(x, z); +checktype(y, z); +checktype(y, g); +checktype(g, z); \ No newline at end of file diff --git a/Week1/homework/js-exercises/errordebug.js b/Week1/homework/js-exercises/errordebug.js new file mode 100644 index 000000000..b482e79ef --- /dev/null +++ b/Week1/homework/js-exercises/errordebug.js @@ -0,0 +1,4 @@ +"use strict"; + +//exercise 2:Error debugging +console.log("I'm awesome!"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logNumber.js b/Week1/homework/js-exercises/logNumber.js new file mode 100644 index 000000000..2b65981f6 --- /dev/null +++ b/Week1/homework/js-exercises/logNumber.js @@ -0,0 +1,10 @@ +"use strict"; + +//exercise3: log the number +var numberX; +console.log('the value of numberX is not defined'); +console.log(numberX); +numberX = 10; +console.log('Now the value of numberX is ten'); +console.log(numberX); + diff --git a/Week1/homework/js-exercises/logRemainder.js b/Week1/homework/js-exercises/logRemainder.js new file mode 100644 index 000000000..4500f6f15 --- /dev/null +++ b/Week1/homework/js-exercises/logRemainder.js @@ -0,0 +1,14 @@ +'use strict'; + +// Exercise 9: Log the remainder +let x =7; //declare x and initialize it to 7 +x= x%3; // value x will be the remainder of x divided by 3 i.e 7%3 +console.log(x); //value of x will be 1 + +let y = 21; //declare y and initialize it to 21 +y = y % 4; // value y will be the remainder of y divided by 4 i.e 21%4 +console.log(y); //value of y will be 1 + +let z = 7; //declare z and initialize it to 13 +z = z % 3; // value z will be the remainder of z divided by 2 i.e 13%2 +console.log(z); //value of z will be 1 \ No newline at end of file diff --git a/Week1/homework/js-exercises/logString.js b/Week1/homework/js-exercises/logString.js new file mode 100644 index 000000000..512fa8449 --- /dev/null +++ b/Week1/homework/js-exercises/logString.js @@ -0,0 +1,9 @@ +"use strict"; + +// Exercise 4: Log the string +var myString ="Ayda Hagos"; +console.log('The value of myString is my full name'); +console.log(myString); +myString = "Lelida"; +console.log("The value of myString changed to my daughter's name"); +console.log(myString); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logarray.js b/Week1/homework/js-exercises/logarray.js new file mode 100644 index 000000000..8cf0f39a1 --- /dev/null +++ b/Week1/homework/js-exercises/logarray.js @@ -0,0 +1,10 @@ +'use strict'; + +// Exercise 6: Log an array of animals +var fruits = []; +console.log('my favorite fruits'); +console.log(fruits); +var myFavAnimals = ['dog', 'cat', 'Lion']; +console.log(myFavAnimals); +myFavAnimals.push("piglet"); +console.log(myFavAnimals); diff --git a/Week1/homework/js-exercises/loghello.js b/Week1/homework/js-exercises/loghello.js new file mode 100644 index 000000000..c28e5e562 --- /dev/null +++ b/Week1/homework/js-exercises/loghello.js @@ -0,0 +1,12 @@ +//hello world in 10 different languages +"use strict"; +console.log("Hallo Wereld!"); //dutch +console.log("Kamusta mundo!"); //Filipino +console.log("Kamusta mundo!"); //Danish +console.log("Bonjour le monde!"); //French +console.log("Dia duit ar domhan!"); //Irish +console.log("salve mundi!"); //Latin +console.log("Hello dinja!"); //Maltese +console.log("Hei Verden!"); //French +console.log("ሰላም ዓለም!"); //Amharic +console.log("Salamu, Dunia!"); //Swahili diff --git a/Week1/homework/js-exercises/loglength.js b/Week1/homework/js-exercises/loglength.js new file mode 100644 index 000000000..d78dfd0c8 --- /dev/null +++ b/Week1/homework/js-exercises/loglength.js @@ -0,0 +1,7 @@ +'use strict'; + +// Exercise 7: Log the length of a strin +var mySentence = "Programming is so interesting"; //declare a variable mysentence and initialize it +console.log(mySentence.length); //prints out the length of mySentece + + diff --git a/Week1/homework/js-exercises/roundAnumber.js b/Week1/homework/js-exercises/roundAnumber.js new file mode 100644 index 000000000..496d85451 --- /dev/null +++ b/Week1/homework/js-exercises/roundAnumber.js @@ -0,0 +1,14 @@ +'use strict'; + +// Exercise 5: Round a number and log it +var z = 7.25; +console.log('the value of z is ' + z); +var a = Math.round(z); +console.log(a); +if (a >z){ + var b = a; +} +else{ + var b=z; +} +console.log("the highest number is "+ b); From 1d9ffa3140a72e261ba23bfcd1b61105a9025b41 Mon Sep 17 00:00:00 2001 From: Ayda Date: Tue, 15 Sep 2020 22:06:42 +0200 Subject: [PATCH 2/2] week 1 exercise 8 check type edited --- Week1/homework/js-exercises/checktype.js | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Week1/homework/js-exercises/checktype.js b/Week1/homework/js-exercises/checktype.js index 9ede0b368..960516535 100644 --- a/Week1/homework/js-exercises/checktype.js +++ b/Week1/homework/js-exercises/checktype.js @@ -10,16 +10,27 @@ var g = { favArtist: 'Beyonce' }; -function checktype(a, b){ -if (typeof a == typeof b){ - console.log('SAME TYPE') -} -else{ +function checktype(a, b, c, d){ + if (typeof a == typeof b) { + console.log('SAME TYPE ' + typeof a); + } + else if (typeof a == typeof c) { + console.log('SAME TYPE ' + typeof a); + } + else if (typeof a == typeof d) { + console.log('SAMETYPE ' + typeof a); + } + else if (typeof b == typeof c) { + console.log('SAME TYPE ' + typeof c); + } + else if (typeof b == typeof d) { + console.log('SAME TYPE ' + typeof b); + } + else if (typeof c == typeof d) { + console.log('SAME TYPE ' + typeof c); + } + else{ console.log('Not the same ...') + } } -} -checktype(x, y); -checktype(x, z); -checktype(y, z); -checktype(y, g); -checktype(g, z); \ No newline at end of file +checktype(x, y, z, g); \ No newline at end of file