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..960516535 --- /dev/null +++ b/Week1/homework/js-exercises/checktype.js @@ -0,0 +1,36 @@ +'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, 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, z, g); \ 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);