Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Week1/homework/js-exercises/arrayCompare.js
Original file line number Diff line number Diff line change
@@ -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');
}
36 changes: 36 additions & 0 deletions Week1/homework/js-exercises/checktype.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions Week1/homework/js-exercises/errordebug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

//exercise 2:Error debugging
console.log("I'm awesome!");
10 changes: 10 additions & 0 deletions Week1/homework/js-exercises/logNumber.js
Original file line number Diff line number Diff line change
@@ -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);

14 changes: 14 additions & 0 deletions Week1/homework/js-exercises/logRemainder.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Week1/homework/js-exercises/logString.js
Original file line number Diff line number Diff line change
@@ -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);
10 changes: 10 additions & 0 deletions Week1/homework/js-exercises/logarray.js
Original file line number Diff line number Diff line change
@@ -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);
12 changes: 12 additions & 0 deletions Week1/homework/js-exercises/loghello.js
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions Week1/homework/js-exercises/loglength.js
Original file line number Diff line number Diff line change
@@ -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


14 changes: 14 additions & 0 deletions Week1/homework/js-exercises/roundAnumber.js
Original file line number Diff line number Diff line change
@@ -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);