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
22 changes: 22 additions & 0 deletions arthimetic-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ 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 ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be 17 % 3 because we're asking for the remainder.

let d= b - a ;
let e= a + b + c +d ;

console.log(e)
/*******************************************************************************
Task 2:
1. Subtract two numbers and log the result to the console.
Expand All @@ -28,3 +34,19 @@ 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

let x= 4-3
console.log(x)

let y= 1*3*5*7
console.log(y);

let rectangular= 3*5*7
console.log(rectangular);
let declare=9.99%0.20

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Declare a variable price and assign it the value 9.99.
This should be something like:
let price = 9.99;


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Declare another variable discount and assign it the value 0.20 and calculate the discounted price and log the result to the console.

console.log(declare);

let s= 10/3

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is not what was required, please declare two variables like I mentioned in the comments above.
Then create a new variable called result which would divide the two numbers and round the result to the nearest integer using Math.round()

console.log(s);

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

<script src="./logical-comaprison-operators.js"></script>
</body>
</html>
49 changes: 33 additions & 16 deletions logical-comaprison-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ 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 --fales>

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 --fales>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should return true, because both of these values are falsey values by default, meaning that false == false.

This would return false only when using the strict equals operator === which would also check for the types resulting in them being false.


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, this should be false because they're two different types of values.


const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE -->
const exp9 = NaN === NaN; // 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.

This should evaluate to false.
The reason NaN === NaN evaluates to false is because according to the IEEE 754 standard (which JavaScript follows for floating-point arithmetic), NaN values are considered unordered. This means that they are not equal to any other value, including other NaN values.


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 --fales>

const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE -->
const exp12 = "apple" > "pineapple"; // 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.

This should be false.
In the expression "apple" > "pineapple", JavaScript compares the strings character by character from left to right. Since "a" comes before "p" in the alphabet, "apple" is considered "less than" "pineapple".


const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE -->
const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE --fales>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should evaluate to true.
Even though numerically 2 is less than 12, since we're comparing strings, the comparison is based on their lexicographical order. In this case, the string "2" is considered greater than the string "12" because "2" comes after "1".


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

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

/*******************************************************************************
Task 2:
Expand All @@ -48,32 +48,49 @@ 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


// - 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
let numlees = num < 5
console.log(numlees);

// - Check if str is either "apple" or "orange" using the logical OR operator. Log the result to the console.
// TODO: ADD YOUR CODE BELOW
let stror = "apple"||"orange"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checking the str to see if it's "apple" or "orange" should be written as the following:

console.log( str === "apple" || str === "orange")

console.log(stror);

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

// - 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
let numeven = 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.

You forgot to check if the number is even, you can do so by writing the following:

console.log( num % 2 === 0 && num > 10 )

console.log(numeven);

// - 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

let numdivisible = num/3 && num/5

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To check if a number is divisible by another number, you should use the mod operator % and check if the value is equal to 0.

console.log( num % 3 === 0 && num % 5 === 0 )

console.log(numdivisible);

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

console.log(str.search("e"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using the search method with strings is a good approach, the return value of the search method is the index of the letter inside the string.
And since there's no "e" in our str variable, it will return -1.
We can use that with a comparison operator to print out true or false in the console:

console.log( str.search("e") !== -1 )

This will return true if it exists, and false if it doesn't.


// - 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<= -1 || num % 1 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To check if the number is odd correctly you can do the following:

console.log( num % 2 === 1 )

Or

console.log( num % 2 !== 0 )

either way these expression will return true or false


// - 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 );
19 changes: 19 additions & 0 deletions variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
2. Use console.log() to output the value of each variable.
********************************************************************************/
// TODO: ADD YOUR CODE BELOW
let personName=("ameer")
console.log(personName);

let age=("27")
console.log(age);

let isHappy=("yessss")
console.log(isHappy);
/*******************************************************************************
Task 2 (Reassigning variables):

Expand All @@ -24,6 +31,8 @@
2. Use console.log o output the value of 'nickName'
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW
let nickName=("ahmed")
console.log(personName);

/*******************************************************************************
Task 3 (Naming variables):
Expand All @@ -33,6 +42,11 @@
2. Declare a variable that stores the age of a user. What name would you choose for this variable?
*******************************************************************************/
// TODO: ADD YOUR CODE BELOW
let favoriteMovie=("fast&furies")
console.log(favoriteMovie);

let storesAge=("18")
console.log(storesAge);

/*******************************************************************************
Task 4 (String Concatenation):
Expand All @@ -48,3 +62,8 @@ 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("how are you")
let finalMsg=`${msg} are you happy`
console.log(finalMsg);
console.log(`Dear ${personName.toUpperCase()}, here your message: ${finalMsg}`)