skip to Main Content

I’m trying to solve what is a fairly easy question. My task:

Write an expression which combines two
boolean
expressions using &&, and
evaluates
to true.

My code:

const number1 = 2
const number2 = 2
const numcheck = number1 === number2 // true

const number3 = 3
const number4 = 3

const numcheck2 = number3 === number4 // true

const finalCheck = numcheck && numcheck2 //true

However, this isn’t being accepted – where am I going wrong?

All my thanks,

2

Answers


  1. Your code looks correct, and the finalCheck expression should evaluate to true. The issue might be related to how you are testing or using the result. Make sure you are checking the value of finalCheck in the right context.

    Here’s the code snippet you provided:

    const number1 = 2
    const number2 = 2
    const numcheck = number1 === number2 // true
    
    const number3 = 3
    const number4 = 3
    
    const numcheck2 = number3 === number4 // true
    
    const finalCheck = numcheck && numcheck2 // true
    

    If you are testing the value of finalCheck and it’s not giving the expected result, you may want to inspect the values of numcheck and numcheck2 individually to see if they are indeed both true before the && operation.

    You can add some console.log statements to help debug:

    console.log("numcheck:", numcheck);
    console.log("numcheck2:", numcheck2);
    
    const finalCheck = numcheck && numcheck2;
    
    console.log("finalCheck:", finalCheck);
    

    Check the console output to see the values of numcheck, numcheck2, and finalCheck. If everything is correct, finalCheck should be true. If you’re still facing issues, provide more details about how you are testing the result or any error messages you’re encountering.

    Login or Signup to reply.
  2. As Tim just said you code seems to work fine, but please try to end the lines with a semicolon ‘;’ and see if it that helps.

    If not try running this example i wrote in Google Chrome or Firefox and see if it works and then modify it as needed:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Javascript example</title>
    </head>
    <body>
        <script>
            const number1 = 2;
            const number2 = 2;
            const numcheck = number1 === number2; // true
    
            const number3 = 3;
            const number4 = 3;
    
            const numcheck2 = number3 === number4; // true
    
            const finalCheck = numcheck && numcheck2; //true
    
            console.log(numcheck);
            console.log(numcheck2);
            console.log(finalCheck);
        </script>
    </body>
    </html>
    

    Please note that === is used to check both type and value equality, while == only checks the value.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search