Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Closed
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
12 changes: 12 additions & 0 deletions task1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//1 write a console.log statement saying "Hello World!" for each language that you know.

let EnglishGreeting = "Hello world!";
console.log (EnglishGreeting)
let ArabicGreeting = "مرحباً بالعالم";
console.log (ArabicGreeting)
let ItalianGreeting = "Ciao Mondo!";
console.log (ItalianGreeting)
let TurkishGreeting = "Selam Dünya!";
console.log (TurkishGreeting)
let DutchGreeting = "Hallo Wereld!";
console.log (DutchGreeting);
14 changes: 14 additions & 0 deletions task10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 10. Write a program to answer the following questions:
10.1 Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer.
10.2 Can you compare infinities? (Not in Eyad's world) - does 6/0 === 10/0? How can you test this?
10.3 Add console.log statements to the above program in which you show that you understand the concepts (just like you've done in the above assignments).*/

let multipleTypesArray = ['class', 21 , true];
console.log(typeof(multipleTypesArray[0]));
console.log(typeof(multipleTypesArray[1]));
console.log(typeof(multipleTypesArray[2]));

//10.2
let x1 = 6/0;
let y1 = 10/0;
x1 === y1? console.log('Yes') : console.log('No');
7 changes: 7 additions & 0 deletions task2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*2 cosider the following code: console.log('I'm awesome');
copy the code in your .js file and run it.
you will see that you get a syntaxError.
find a solution for this error.
Hint:read the error message carefully, it also gives an indication of where the problem is.*/

console.log ('I\'m awesome');
19 changes: 19 additions & 0 deletions task3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//3 Declare a variable x and initialize it with an integer, using these steps:
//3.1 First, Declare your variable x (do not initialize it yet)
//3.2 add a console.log statement that explains in words what you think the value of x is.
//3.3 add a console.log statement that logs the value of x.
//3.4 Now initialize your variable x with an integer.
//3.5 Next, add console.log statement that explains what you think the value of x is.
//3.6 add a console log staement that logs the value of x.

let x ;

console.log ("the value of my variable x will be:an Integer");

console.log (x);

x = 8 ;

console.log ("the value of my variable x will be:an Integer");

console.log (x);
23 changes: 23 additions & 0 deletions task4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//4 Declare a variable y and assign a string to it.
//4.1 Write a console.log statement in which you explain in words what you think the value of the string is.
//4.2 Now console.log the variable y.
//4.3 Now assign a new string to the variable y.
//4.4 Write a console.log statement that explains in words what you think will be logged to the console.
//Now console.lg y again

let y = "HackYourFuture";


console.log ("the value of the string is: " + "HackYourFuture");


console.log (y);


y = "HYF";


console.log ("the value of the string is: " + "HYF");


console.log (y);
27 changes: 27 additions & 0 deletions task5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//5 How do you round the number 7.25 to the nearest integer,
//5.1 Declare a variable z and assign the number 7.25 to it.
//5.2 Console.log z.
//5.3 Declare another variable a that has the value of z but rounded to the nearest integer.
//5.4 console.log a.
//5.5 So now we have z and a find a way to compare the two values and store the highest of the two in a new variable.
//5.6 console.log the highest value.

let z = 7.25;

console.log(z);

let a = (Math.round(z));

console.log(a);

let highest;
if (z > a) {
highest = z ;
}
else {
highest = a ;
};

console.log(highest);

//You can also use math.max, but this solution is fine
16 changes: 16 additions & 0 deletions task6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//6
let favoriteAnimals = [ ];

console.log("the value of my array is : Empty.");

console.log(favoriteAnimals);

let myFavoriteAnimals = [ 'Deer' , 'Horse' , 'Koala' ];

console.log (myFavoriteAnimals);

let newMyFavoriteAnimals = myFavoriteAnimals.concat(['baby pig']);

console.log (newMyFavoriteAnimals);

// you can also use myFavoriteAnimals.push('baby pig'); Which might be an easier solution.
9 changes: 9 additions & 0 deletions task7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* 7. More strings
Let's consider the following string: let myString = "this is a test".
7.1 Add the string to your file and console.log it.
7.2 Find a way to get the length of myString.
7.3 console.log the length of myString.*/

let myString = "this is a test";
console.log(myString);
console.log(myString.length);
65 changes: 65 additions & 0 deletions task8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* 8. Write a program that checks the types of two variables and prints out SAME TYPE if they are the same type.
8.1 First declare at least four variables and assign them different data types.
8.2 For each variable write a console.log statement that logs the value
8.3 Now write a console.log statement wherein you first explain in words what you think the type of your variables is.
8.4 Now use typeof to log the actual type of your variables.
8.5 Now compare the types of your different variables with one another.
8.6 Make sure to also show a message when the variables you are comparing are not the same type.*/


let type1 = 21 ;
console.log ("The value of my variable type1 is: " + type1);
console.log (typeof(type1));
let type2 = ['HTML', 'CSS'] ;
console.log ("The value of my variable type2 is: " + type2);
console.log (typeof(type2));
let type3 = " Hello JavaScript " ;
console.log ("The value of my variable type3 is: " + type3);
console.log (typeof(type3));
let type4 = "Class21" ;
console.log ("The value of my variable type4 is: " + type4);
console.log (typeof(type4));

//8.5
if (typeof(type1)===typeof(type2)) {
console.log('type1 and type2 are SameType');
}
else {
console.log('type1 and type2 are NOT SameType');
}

if (typeof(type1)===typeof(type3)) {
console.log('type1 and type3 are SameType');
}
else {
console.log('type1 and type3 are NOT SameType');
}

if (typeof(type1)===typeof(type4)) {
console.log('type1 and type4 are SameType');
}
else {
console.log('type1 and type4 are NOT SameType');
}

if (typeof(type2)===typeof(type3)) {
console.log('type2 and type3 are SameType');
}
else {
console.log('type2 and type3 are NOT SameType');
}

if (typeof(type2)===typeof(type4)) {
console.log('type2 and type4 are SameType');
}
else {
console.log('type2 and type4 are NOT SameType');
}

if (typeof(type3)===typeof(type4)) {
console.log('type3 and type4 are SameType');
}
else {
console.log('type3 and type4 are NOT SameType');
}

8 changes: 8 additions & 0 deletions task9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* 9. If x equals 7, and the only other statement is x = x % 3, what would be the new value of x?
9.1 Add at least 3 console.log statements in which you show that you understand what % does.*/

let x = 7 ;
x = x % 3;
console.log(x = x % 3);
console.log(x %= 3);
console.log(x);
121 changes: 121 additions & 0 deletions week2homework.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you did all your homework in one file, but the assignment was to make one file for each part of the homework:

For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, I'v made changes as advised, could you please re-check?

let EnglishGreeting = "Hello world!";
console.log (EnglishGreeting)
let ArabicGreeting = "مرحباً بالعالم";
console.log (ArabicGreeting)
let ItalianGreeting = "Ciao Mondo!";
console.log (ItalianGreeting)
let TurkishGreeting = "Selam Dünya!";
console.log (TurkishGreeting)
let DutchGreeting = "Hallo Wereld!";
console.log (DutchGreeting)

//2
console.log ('I\'m awesome');

//3
let x ;
console.log ("the value of my variable x will be:EvenNumber");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the value of x is EvenNUmber ?
(I don't think it will be that value)

console.log (x);
x = 8 ;
console.log ("the value of my variable x will be:EvenNumber");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the value of x is EvenNumber?

console.log (x)

//4
let y = "HackYourFuture"
console.log ("the value of the string is "+"HackYourFuture")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget to add ; at the end of the line:)

console.log (y)
y = "HYF"
console.log ("the value of the string is "+"HYF")
console.log (y)

//5
let z = 7.25;
console.log(z);
let a = (Math.round(z));
console.log(a);

let highest;
if (z>a){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! You can also use math.max, but this solution is fine:)

highest=z;
}
else{
highest=a;
}
console.log(highest);


//6
let FavoriteAnimals = [ ]; //6.1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not use capital letters for the variable names.

So FavoriteAnimals should be favoriteAnimals.

See The naming conventions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix this one?

console.log("the value of my array is : Empty."); //6.2
console.log(FavoriteAnimals); //6.3
let MyFavoriteAnimals = [ 'Deer' , 'Horse' , 'Koala' ]; //6.4
console.log (MyFavoriteAnimals); //6.5
let NewMyFavoriteAnimals = MyFavoriteAnimals.concat(['baby pig']); //6.6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, you can also use
MyFavoriteAnimals.push('baby pig');

Which might be an easier solution

console.log (NewMyFavoriteAnimals); //6.7

//7
let myString = "this is a test";
console.log(myString);
console.log(myString.length);

//8
let type1 = 21 ;
console.log ("The value of my variable type1 is: " + type1);
console.log (typeof(type1));
let type2 = ['HTML', 'CSS'] ;
console.log ("The value of my variable type2 is: " + type2);
console.log (typeof(type2));
let type3 = " Hello JavaScript " ;
console.log ("The value of my variable type3 is: " + type3);
console.log (typeof(type3));
let type4 = "Class21" ;
console.log ("The value of my variable type4 is: " + type4);
console.log (typeof(type4));

//8.5
if (typeof(type1)===typeof(type2))
{console.log('type1 and type2 are SameType');}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: The code is easier to read if you add more spaces in between the if statement, like this:

if (typeof(type1)===typeof(type3)) {
  console.log('type1 and type3 are SameType');
} else {
  console.log('type1 and type3 are NOT SameType');
}

else {console.log('type1 and type2 are NOT SameType');}

if (typeof(type1)===typeof(type3))
{console.log('type1 and type3 are SameType');}
else {console.log('type1 and type3 are NOT SameType');}

if (typeof(type1)===typeof(type4))
{console.log('type1 and type4 are SameType');}
else {console.log('type1 and type4 are NOT SameType');}

if (typeof(type2)===typeof(type3))
{console.log('type2 and type3 are SameType');}
else {console.log('type2 and type3 are NOT SameType');}

if (typeof(type2)===typeof(type4))
{console.log('type2 and type4 are SameType');}
else {console.log('type2 and type4 are NOT SameType');}

if (typeof(type3)===typeof(type4))
{console.log('type3 and type4 are SameType');}
else {console.log('type3 and type4 are NOT SameType');}





//9
let X = 7 ;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use lowercase x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one, then the homework is approved!

X = X % 3;
console.log(X = X % 3);
console.log(X %= 3);
console.log(X);

//10.1
let multipleTypesArray = ['class', 21 , true];
console.log(typeof(multipleTypesArray[0]));
console.log(typeof(multipleTypesArray[1]));
console.log(typeof(multipleTypesArray[2]));

//10.2
let x1 = 6/0;
let y1 = 10/0;
x1 === y1? console.log('Yes') : console.log('No');