I am learning Javascript Fundamentals, where I read an article at developer.mozilla.org.
Now at the end they have suggested 3 tests.
At test 1, I am stuck at " write a calculation that checks whether finalResult
is an even number. Store the result in a variable called evenOddResult
"
So, guys can you help with this?
All details at: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Test_your_skills:_Math
And here is the whole question:
- 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 calledevenOddResult
.
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);