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
21 changes: 21 additions & 0 deletions arthimetic-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Task 1:
7. Use console.log() to print the value of variable e to the console. (it should result 102.000)
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW
let a =4+6;
let b =10*5;
let c =17%3;
let d =b-a;
let e =a+b+c+d;

console.log(e);



/*******************************************************************************
Task 2:
Expand All @@ -28,3 +37,15 @@ Task 1:
5. Divide two numbers and round the result to the nearest integer before logging it to the console.
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW

console.log(10-5);
console.log(3*5*7*9);
let h=3;
let w=5;
let l=7;
console.log(h*w*l);

let value = 9.99 - 0.20;
console.log(value);
console.log(24 % 3);

5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<title>Variables and Operators</title>
</head>
<body>
<script src="./variables.js"></script>
<script src="arthimetic-operators.js"></script>
<script src="variables.js"></script>
<script src="logical-comaprison-operators.js"></script>

<!-- <script src="./arthimetic-operators.js"></script> -->
<!-- <script src="./logical-comaprison-operators.js"></script> -->
</body>
Expand Down
48 changes: 26 additions & 22 deletions logical-comaprison-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,34 @@ TASK 1:
// Have fun! // 😃
********************************************************************************/

const exp1 = 10 >= 10; // TODO: ADD YOUR EVALUATION HERE -->
const exp1 = 10 >= 10; // TODO: ADD YOUR EVALUATION HERE -->true

const exp2 = "dog" == "dog"; // TODO: ADD YOUR EVALUATION HERE -->
const exp2 = "dog" == "dog"; // TODO: ADD YOUR EVALUATION HERE -->true

const exp3 = true != false; // TODO: ADD YOUR EVALUATION HERE -->
const exp3 = true != false; // TODO: ADD YOUR EVALUATION HERE -->true

const exp4 = "10" === 10; // TODO: ADD YOUR EVALUATION HERE -->
const exp4 = "10" === 10; // TODO: ADD YOUR EVALUATION HERE -->false

const exp5 = 5 > 4; // TODO: ADD YOUR EVALUATION HERE -->
const exp5 = 5 > 4; // TODO: ADD YOUR EVALUATION HERE -->true

const exp6 = null == undefined; // TODO: ADD YOUR EVALUATION HERE -->
const exp6 = null == undefined; // TODO: ADD YOUR EVALUATION HERE -->true

const exp7 = "true" == true; // TODO: ADD YOUR EVALUATION HERE -->
const exp7 = "true" == true; // TODO: ADD YOUR EVALUATION HERE -->true

@AlhassanAli01 AlhassanAli01 Feb 9, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"true" is a string value and true is a boolean value, they do not equal the same thing, therefore this should evaluate to false


const exp8 = "false" == false; // TODO: ADD YOUR EVALUATION HERE -->
const exp8 = "false" == false; // TODO: ADD YOUR EVALUATION HERE -->true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same goes here, they're two different types, this should be false.


const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE -->
const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE -->true
Comment thread
mohamedali0122 marked this conversation as resolved.

const exp10 = !false || false; // TODO: ADD YOUR EVALUATION HERE -->
const exp10 = !false || false; // TODO: ADD YOUR EVALUATION HERE -->true

const exp11 = false && !false; // TODO: ADD YOUR EVALUATION HERE -->
const exp11 = false && !false; // TODO: ADD YOUR EVALUATION HERE -->false

const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE -->
const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE -->false

const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE -->
const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE -->true
const exp14 = undefined == null; // TODO: ADD YOUR EVALUATION HERE -->true

const exp14 = undefined == null; // TODO: ADD YOUR EVALUATION HERE -->

const exp15 = undefined === null; // TODO: ADD YOUR EVALUATION HERE -->
const exp15 = undefined === null; // TODO: ADD YOUR EVALUATION HERE -->false

/*******************************************************************************
Task 2:
Expand All @@ -47,33 +46,38 @@ const isHappy = false;

// - Check if num is between 10 and 20 (inclusive) using the logical AND operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log(num >=10 && num <=20);
// - Check if num is either less than 5 or greater than 50 using the logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log(num >=5 || num <=50 );
// - Check if str is either "apple" or "orange" using the logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
console.log(str == "apple" || str == "orange");

// - Check if isHappy value is true using the logical NOT operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
console.log(isHappy == !isHappy);

// - Check if num is even and greater than 10 using the logical AND operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
console.log(num / 2 == 0 && num > 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use the mod operator % to check for the remainder instead of the division operator /.


// - Check if num is divisible by both 3 and 5 using the logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
console.log(num / 3 ==0 || num / 5 == 0 )

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The division operator / will only return the result, not the remainder, here we're supposed to check if the number is divisible using the mod operator % and then comparing the remainder.


// - Check if str contains the letter "e". Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log(str.includes("e"))
// - Check if str starts with "Hakuna". Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log( str.startsWith("Hakuna"))
// - Check if str ends with "a". Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log(str.endsWith("a"))
// - Check if num is either negative or odd using the logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW

console.log(num /2 == 1 || num < 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use the mod operator % to check for the remainder instead of the division operator /.

// - Check if the length of str is greater than num or equal to 40 using logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
console.log(str.length > num || str.length ==40)
16 changes: 16 additions & 0 deletions variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
2. Use console.log() to output the value of each variable.
********************************************************************************/
// TODO: ADD YOUR CODE BELOW
let personName ="mohamed ali";
let age =24;
let isHappy = true;

console.log(personName);
console.log(age);
console.log(isHappy);

/*******************************************************************************
Task 2 (Reassigning variables):
Expand All @@ -25,6 +32,9 @@
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW

let nickName = personName;
console.log(nickName);

/*******************************************************************************
Task 3 (Naming variables):

Expand All @@ -34,6 +44,9 @@
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW

let myFilm ="johan waek";
let myAge =34;
console.log(`my best film is ${myFilm}, and my age ${myAge}`);
/*******************************************************************************
Task 4 (String Concatenation):
Build upon the previous task by completing the following steps:
Expand All @@ -48,3 +61,6 @@ Steps:
- Print the final message to the console, including the personName in uppercase in this format `Dear personName_VALUE, here's your message: finalMsg_VALUE.`.
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW
let msg =prompt(" Why are you happy?");
let final_message=`${msg} And btw, Why are you happy?`;
console.log(`Dear ${final_message}, here's your message: ${personName.toUpperCase()}`);