I need help solving a math solution for js

Could someone help my solve the following solution?

So, try updating the live code below to recreate the finished example, following these steps:

  1. Create four variables that contain numbers. Call the variables something sensible.
  2. Add the first two variables together and store the result in another variable.
  3. Subtract the fourth variable from the third and store the result in another variable.
  4. 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.
  5. Finally, write a calculation that checks whether finalResult is an even number. Store the result in a variable called evenOddResult .

What I have so far:

let finalResult;

let evenOddResult;

// Add your code here
var=a;
var=b;
var=c;
var=d;
a=1;
b=3;
c=3;
d=15;


e=a+b
f=d-c

finalResult=e*f

finalResult===

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

@ayandagatsha edit your post and :

insert your code here

I dont understand what you mean?

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

in the evenOddResult variable you need to write a calculation using finalResult and the % operator.

and also i’d get rid of the "finalResult===’ in the code that you wrote.

wrong syntax

wrong syntax

try fixing the syntax

1 Like

Hi @ayandagatsha

I saw your code and why dont we start by

  1. Creating 4 variables and assigning them a number like this.
var resultOne = 1;
var resultTwo = 3;
var resultThree = 3;
var resultFour = 15;
  1. Add the first two variables and store result in a variable called
var firstResult;
  1. Subtract the four and third variables and store result in a variable called
var secondResult;
  1. Multiply firstResult and secondResult and store the result in a variable called
var multiplyFinalResults;
  1. Then you can do an if else statement grabbing the multiplyFinalResults
    and compare them to 48 and if its even or odd.

  2. Before you start manupulating or Creating elements in the DOM for result purposes, its good to test your results in the console, once you have that you can start working on the DOM.

Let us know your process so we can help.

1 Like

So would you say the code below suffices as a solution?

var a=1;
var b=3;
var c=3;
var d=15;


e=a+b
f=d-c

finalResult=e*f

if (finalResult===48) {
eveOddResult= finalResult;
}

Hi yes just like @ilenia had said… the code above has syntax errors and need a better structure code, as well meaning letter variables.
Your code its getting there but need a better structure.

your e and f variables are not even created or defined in the code You will have an error.

why dont you start like i post it on:

//You create your variables and assign them a value.
var resultOne = 1;
var resultTwo = 3;
var resultThree = 3;
var resultFour = 15;

// now we create a first result of resultOne and resultTwo variables like this

var firstResult = resultOne + resultTwo;

console.log(firstResult) // output 4

// now do for the second task by subtraction resultThree and resultFour and store them in a variable called secondResult just like i did by adding.

But there is no need for an if statement(in this excercise) .
And I think it would make more sense if he/she were to store the product of firstResult and secondResult in the variable finalResult because the test case specifically looks for that variable.
Once he/she reaches his finalResult, he/she only needs to set evenOddResult = finalResult % 2 because it checcs if evenOddResult is deeply equal to 0 in the lower portion of the code.

2 Likes

Yes that also can work to as another alternative since he/she was doing the conditional (ternary) operator, i when out to do old style if else because he/she had it as well, but yes no need for a condition because its getting a value and will be determined by the result if its even/odd.

We also have to get in mind he/she wants to get the result to be a 48 as well.

2 Likes

of course, that’s why I only focused on the portion after the initial variable assignment and operations. Their variables were the right values and the math was right, just declared incorrectly initially,.

1 Like