Create four variables that contain numbers. Call the variables something sensible.
Add the first two variables together and store the result in another variable.
Subtract the fourth variable from the third and store the result in another variable.
Multiply the results from the last two steps together, storing the result in a variable called finalResult . The product should be 48. If it isn’t, you’ll have to adjust some of the initial input values.
Finally, write a calculation that checks whether finalResult is an even number. Store the result in a variable called evenOddResult .
let finalResult;
let evenOddResult;
// Add your code here
let a = 6;
let b = 6;
let c = 8;
let d = 12;
x = a + b;
y = d - c;
finalResult = y * x;
if
(finalresult%2===0)
{evenOddResult="even"}
else
{evenOddResult="odd}
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
Hi
In the test they say to add code
Can you show us what did u add so far? and what did u try?
let finalResult;
let evenOddResult;
// Add your code here
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
Is the finalResult 48? Yes, well done!
The final result is odd. Hrm.
And here is the whole code:
let finalResult;
let evenOddResult;
// Add your code here
let a = 6;
let b = 6;
let c = 8;
let d = 12;
x = a + b;
y = d - c;
finalResult = y * x;
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Hi,
So I added your suggested code, and still I am not getting:
SyntaxError: Invalid or unexpected token
Here is the full code I entered in Math test 1:
let finalResult;
let evenOddResult;
// Add your code here
let a = 6;
let b = 6;
let c = 8;
let d = 12;
x = a + b;
y = d - c;
finalResult = y * x;
if
(finalresult%2===0)
{evenOddResult="even"}
else
{evenOddResult="odd}
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
I actually corrected in in the developer mozilla test. So below the what I have written in the test result but still, it’s not right
let finalResult;
let evenOddResult;
// Add your code here
let a = 6;
let b = 6;
let c = 8;
let d = 12;
x = a + b;
y = d - c;
finalResult = y * x;
if
(finalresult % 2 === 0)
{evenOddResult="even"}
else
{evenOddResult="odd"}
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
When I use repl.it, I can see an error with this line (small capitalization typo)
In this repl.it link, I added 'use strict' to help highlight those sorts of issues. There are 3 errors in strict mode, two undefined variables and one typo: https://repl.it/repls/GlumStrikingConstants#index.js
let finalResult;
let evenOddResult;
// Add your code here
let a = 6;
let b = 6;
let c = 8;
let d = 12;
x = a + b;
y = d - c;
finalResult = y * x;
if (finalResult % 2 === 0) {
evenOddResult='The final result is even!'
} else {
evenOddResult='The final result is odd. Hrm.'
}
// Don't edit the code below here!
section.innerHTML = ' ';
let para1 = document.createElement('p');
let finalResultCheck = finalResult === 48 ? `Yes, well done!` : `No, it is ${ finalResult }`;
para1.textContent = `Is the finalResult 48? ${ finalResultCheck }`;
let para2 = document.createElement('p');
let evenOddResultCheck = evenOddResult === 0 ? 'The final result is even!' : 'The final result is odd. Hrm.'
para2.textContent = evenOddResultCheck;
section.appendChild(para1);
section.appendChild(para2);
This line is already handling the output text for you for. It tests your output to see if it matches 0. It looks like you want set evenOddResult to either 0 or 1.