Skip to content

Conversation

@bit-sercererx
Copy link

No description provided.

// TODO: ADD YOUR CODE BELOW
let a= 4 + 6 ;
let b= 10 * 5 ;
let c= 17 / 3 ;

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 rectangular= 3*5*7
console.log(rectangular);
let declare=9.99%0.20

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;

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

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

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()

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>

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 exp6 = null == undefined; // TODO: ADD YOUR EVALUATION HERE --fales>

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

@AlhassanAli01 AlhassanAli01 Feb 9, 2024

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 exp7 = "true" == true; // TODO: ADD YOUR EVALUATION HERE -- true>

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

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 exp8 = "false" == false; // TODO: ADD YOUR EVALUATION HERE -- true>

const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE -->
const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE -- true>

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

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

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

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".


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

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")


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

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 )

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

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 )

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

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

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 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 );

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants