Skip to content
Open
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
14 changes: 14 additions & 0 deletions Week2/10_program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 10.1 Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer.

let myArray = ["My age", 30, ["Student", 5]]; // With array is possibale to store different data, within a single variable
console.log(myArray);


//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
let inf1 = 10 / 0;
let inf2 = 6 / 0;

if (inf2 === inf2)
console.log("inf1 and inf2 are infinity")
else console.log("False")
8 changes: 8 additions & 0 deletions Week2/1_hello_world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
console.log("Hallo Wereld"); // Dutch
console.log("Bonjour le monde"); // French
console.log("مرحبا بالعالم"); // Arabic
console.log("ہیلو دنیا"); // Urdu
console.log("Selam Dünya"); // Turkish
console.log("你好,世界"); // Chinese
console.log("Hallo Welt"); // German

8 changes: 8 additions & 0 deletions Week2/2_SyntaxError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
console.log('I\'m awesome')
// Error type: SyntaxError: missing ) after argument list }

// Reason : here is no "+" operator to concatenate the string
// so JavaScript expects the argument for the log function to be just 'I'.
// In that case, it should be terminated by a closing parenthesis.

// Solution : Adding backslash (\) after 'I
6 changes: 6 additions & 0 deletions Week2/3_declaring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let x; //declare the variable
console.log("My variable x will be my age");// what supposed x to be
console.log(x) // here will get an undefined result because the x was not initialized yet
x=30; // now we have assigned x to an integer
console.log("My variable x will be my age");
console.log(x); // here we get definded result
6 changes: 6 additions & 0 deletions Week2/4_assign_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let y="Mosleh"; //Declare a variable y and assign a string to it.
console.log("My variable y will be my name");// what supposed y to be
console.log(y); // prent actula value of y
y="football"; // Re-assigning y to a different value
console.log("My new variable y will be my hobby")// what new value of y will be
console.log(y); // get new result of y
6 changes: 6 additions & 0 deletions Week2/5_round_numbder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const z = 7.25;
console.log(z);
let a = Math.round(z);
console.log(a);
let biggerNum = Math.max(a,z);
console.log(biggerNum);
8 changes: 8 additions & 0 deletions Week2/6_arry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let zoo=[];
console.log("The value of the array will be []");
console.log(zoo);
zoo=['Lione', 'Tiger', 'Giraffe', 'Elephant'];
console.log(zoo);
zoo.push('baby pig');
console.log(zoo);

2 changes: 2 additions & 0 deletions Week2/7_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let myString = "this is a test";
console.log('the length of myString is'+' '+ myString.length);
33 changes: 33 additions & 0 deletions Week2/8_checkTypeOfData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 8.1 First declare at least four variables and assign them different data types
let num = 5;
let str = "name";
let arr = ["blue", "black", "Red"];
let boo = false;

// 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.
console.log("The value of my variable 'num' is: " + num);
console.log("num is: Number");
console.log("The value of my variable 'str' is: " + str);
console.log("str is: String");
console.log("The value of my variable 'arr' is: " + arr);
console.log("arr is: Array");
console.log("The value of my variable 'boo' is: " + boo);
console.log("boo is: Boolean");

//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.
function compareType(var1,var2) {
if (typeof var1 == typeof var2) {
console.log( "this variable have the same type");
} else {
console.log("The first variable assigned to %o and the second variable assigned to %o ",typeof var1 , typeof var2 );
}
}
compareType(num,str);
compareType(num,arr);
compareType(num,boo);
compareType(str,arr);
compareType(str,boo);
compareType(arr,boo);
13 changes: 13 additions & 0 deletions Week2/9_reminder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let X = 7;
X = X % 3;
console.log(X); ("The new value of X will be the reminder of divides a X by 3 which is 1")

let value1 = 5;
value1 = value1 % 2;
console.log(value1); // The result will be 1
let value2 = 8;
value2 = value2 % 3;
console.log(value2); // The result will be 2
let value3 = 9;
value3 = value3 % 3;
console.log(value3); // The result will be 0
24 changes: 24 additions & 0 deletions Week2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home work javascript week2</title>
</head>
<body>
<main id="main">
<h1>Homework JS1 week 2</h1>
<script src="1_hello_world.js"></script>
<script src="2_SyntaxError.js"></script>
<script src="3_declaring.js"></script>
<script src="4_assign_string.js"></script>
<script src="5_round_numbder.js"></script>
<script src="6_arry.js"></script>
<script src="7_string.js"></script>
<script src="8_checkTypeOfData.js"></script>
<script src="9_reminder.js"></script>
<script src="10_program.js"></script>

</main>
</body>