From 39ef30b67dd8747b295b818cde5ec6974690fdff Mon Sep 17 00:00:00 2001 From: aklilu mezene tsigie Date: Wed, 19 Feb 2020 17:11:15 +0200 Subject: [PATCH] javaScript-1 home work week-1 --- Week1/homework/js-exercises/compareArrays.js | 11 ++++ Week1/homework/js-exercises/errorDebugging.js | 3 ++ Week1/homework/js-exercises/lengthStrings.js | 3 ++ Week1/homework/js-exercises/logArray.js | 8 +++ Week1/homework/js-exercises/logHello.js | 11 ++++ Week1/homework/js-exercises/logNumber.js | 7 +++ Week1/homework/js-exercises/logRemainder.js | 12 +++++ Week1/homework/js-exercises/logString.js | 9 ++++ Week1/homework/js-exercises/roundNumber.js | 7 +++ Week1/homework/js-exercises/typeChecker.js | 50 +++++++++++++++++++ 10 files changed, 121 insertions(+) create mode 100644 Week1/homework/js-exercises/compareArrays.js create mode 100644 Week1/homework/js-exercises/errorDebugging.js create mode 100644 Week1/homework/js-exercises/lengthStrings.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/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/roundNumber.js create mode 100644 Week1/homework/js-exercises/typeChecker.js diff --git a/Week1/homework/js-exercises/compareArrays.js b/Week1/homework/js-exercises/compareArrays.js new file mode 100644 index 000000000..22d959f01 --- /dev/null +++ b/Week1/homework/js-exercises/compareArrays.js @@ -0,0 +1,11 @@ +'use strict' +const aray1 = ["hello", 123, true,{ name:"Noer"}]; +var cars = ["Volvo","Toyota","Fiat","Mercedes","BMW","Saab","Ford"]; +// the method to obtain array length is ' length()'. + console.log('The length of the array "arrayy1" is :' + (aray1.length)); + console.log('And the length of the array "cars" is :' + (cars.length)); +if(cars.length == aray1.length){ +console.log("They are the same!"); +} else{ + console.log("Two different Sizes"); +} \ No newline at end of file diff --git a/Week1/homework/js-exercises/errorDebugging.js b/Week1/homework/js-exercises/errorDebugging.js new file mode 100644 index 000000000..291c58014 --- /dev/null +++ b/Week1/homework/js-exercises/errorDebugging.js @@ -0,0 +1,3 @@ +'use strict' +console.log('I'am awesome'); +console.log("I'am awesome"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/lengthStrings.js b/Week1/homework/js-exercises/lengthStrings.js new file mode 100644 index 000000000..ade544a7d --- /dev/null +++ b/Week1/homework/js-exercises/lengthStrings.js @@ -0,0 +1,3 @@ +'use strict' +var mySentence = "Programming is so interesting"; +console.log("The String length of the string " + '"' + mySentence + '"' + "is: " + `${mySentence.length}`); \ 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..10e011587 --- /dev/null +++ b/Week1/homework/js-exercises/logArray.js @@ -0,0 +1,8 @@ +'use strict' +var cars = []; +console.log("The array has no items to display or it is an empty array "); +console.log(cars); +var animals = ["Cow","Donkey","Sheep"]; +console.log("An array of three animals : " + animals); +animals.push("Piglet"); +console.log("Array of animals after a 'Piglet' is added to it : " + animals); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logHello.js b/Week1/homework/js-exercises/logHello.js new file mode 100644 index 000000000..e74e1c627 --- /dev/null +++ b/Week1/homework/js-exercises/logHello.js @@ -0,0 +1,11 @@ +'use strict' +console.log("Hello World!"); +console.log("Geia, sou Kosme!");/* Greek */ +console.log("Ni hao, shijie!");/* chinese */ +console.log("Bonjour ,le monde!");/* French */ +console.log("Privet, mir!")/*Russian*/ +console.log("שלום ;עולם!")/*Hebrew*/ +console.log("Salamu, Dunia!")/*swahili*/ +console.log("ሰላም፤ ዓለም!")/*Amharic*/ +console.log("Hallo, Welt!")/*German*/ +console.log("Ciao, mondo!");/* Italy*/ \ 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..1f833ee9b --- /dev/null +++ b/Week1/homework/js-exercises/logNumber.js @@ -0,0 +1,7 @@ +'use strict' +var numberX; +console.log("Enter an Integer Number:"); +console.log('7'); +var numberX = 7; +console.log("The value the variable numberX is:"); +console.log(numberX); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logRemainder.js b/Week1/homework/js-exercises/logRemainder.js new file mode 100644 index 000000000..a8065e5bf --- /dev/null +++ b/Week1/homework/js-exercises/logRemainder.js @@ -0,0 +1,12 @@ +'use strict' +var x = 7; +x = x % 3; +console.log("The result of 'x = x % 3' is:") +console.log(x); +// i used modulo operator to obtain +//the remainder when 7 is divided by 3 +var y = 21; +y = y % 4; +console.log(`The remainder of 21 divided by 4 is: ${21 % 4}`); +// i used modulo operator to obtain +//the remainder when 21 is divided by 4 diff --git a/Week1/homework/js-exercises/logString.js b/Week1/homework/js-exercises/logString.js new file mode 100644 index 000000000..d13d63a9f --- /dev/null +++ b/Week1/homework/js-exercises/logString.js @@ -0,0 +1,9 @@ +'use strict' +var myString = "Aklilu Mezene Tsigie"; +console.log("My Full Name is:"); +console.log(myString); +myString = "A String is a text inside a double or single quote"; +console.log("What is a String?") ; +console.log(myString); + + diff --git a/Week1/homework/js-exercises/roundNumber.js b/Week1/homework/js-exercises/roundNumber.js new file mode 100644 index 000000000..f7dfe77e8 --- /dev/null +++ b/Week1/homework/js-exercises/roundNumber.js @@ -0,0 +1,7 @@ +'use strict' +var z = 7.25; +console.log(z); +var a = Math.round(z); +console.log(a); +var y = Math.max(z,a); +console.log(y); \ No newline at end of file diff --git a/Week1/homework/js-exercises/typeChecker.js b/Week1/homework/js-exercises/typeChecker.js new file mode 100644 index 000000000..ebaf20ff4 --- /dev/null +++ b/Week1/homework/js-exercises/typeChecker.js @@ -0,0 +1,50 @@ +'use strict' +let capitalCity1="Tokyo"; +let capitalCity2="Mexico City"; +var person = {firstName:'John' , lastName:'Doe' , age:'50' , eyeColor:'blue'}; +var airPort = {city:'Athens', runWayLength:'4Km', elevation:'94m'}; + +//logging two different data type out of the six variables declared + +console.log(typeof (capitalCity2)); +console.log(typeof (person)); + +//comparing data types of Each Variables + +if(typeof (capitalCity1) == typeof (person)){ + console.log('The data type of variable +" "+ "capitalCity1" is: the SAME TYPE as variable "person"'); + } else { + console.log("The data type of" + 'variable "capitaCity1" is:' + "Not the same as" + 'variable "person"'); + } +if(typeof (capitalCity1) == typeof (capitalCity2)){ + console.log("The data type of" + 'variable "capitalCity1" is:' + "the SAME TYPE as" + 'variable "capitalCity2"'); + } else { + console.log("The data type of" + 'Variable "capitalCity1" is:' + "Not the same as" + 'Variable "capitalCity2"'); + } +if(typeof (capitalCity1) == typeof (airPort)){ + console.log("The data type of" + 'variable "capitalCity1" is:' + "the SAME TYPE as" + 'variable "airPort"'); + } else { + console.log("The data type of" + 'Variable "capitalCity1" is:' + "Not the same as" + 'variable "airPort"'); + } +if(typeof (capitalCity2) == typeof (person)){ + console.log("The data type of" + 'variable "capitalCity2" is:' + "the SAME TYPE as" + 'variable "person"'); + } else { + console.log("The data type of" + 'variable "capitalCity2" is:' + "Not the same as" + 'variable "person"'); + } +if(typeof (capitalCity2) == typeof (airPort)){ + console.log("The data type of" + 'variable "capitalCity2" is:' + "the SAME TYPE as" + 'variable "airPort"'); + } else { + console.log("The data type of" + 'variable "capitalCity2" is:' + "Not the same as" + 'variable "airPort"'); + } + +if(typeof (person) == typeof (airPort)){ + console.log("The data type of" + 'variable "person" is:' + "the SAME TYPE as" + 'variable "airPort"'); + } else { + console.log("The data type of" + 'variable "person" is:' + "Not the same as" + 'variable "airPort"'); + } + + + + + + \ No newline at end of file