 # Can I get an Evaluation for Math Exercise 2

``````<meta charset="utf-8" />

<style>

p {

color: purple;

margin: 0.5em 0;

}

* {

box-sizing: border-box;

}

</style>

``````
``````<section class="preview">

</section>
``````

Math 2

1 Like

This isn’t quite right. Let me walk you through the steps:

1. Write a calculation that multiplies `result` and `result2` together and assigns the result back to `result` . This will require assignment shorthand.

I’m not sure why you used the `if` statement here. It always run because what’s inside the parenthesis is always `true`. We just need to multiply the two numbers and assign them. This would be the correct assignment: `result *= result2;` It is the short version of `result = result * result2;` which would also work.

1. Write a line of code that takes result and formats it to 2 decimal places, storing the result of this in a variable called `finalResult` .

To format the number we need the `toFixed()` method.

1. Check the data type of `finalResult` using `typeof` ; you’ll probably see that it is actually of `string` type! Write a line of code that converts it to a `number` type, storing the result in a variable called `finalNumber` .

Since the `toFixed()` method returns a string we need the `Number()` constructor to convert the string to a number.

1. The value of `finalNumber` needs to be `10.42` . Go back and update the original calculations you were provided with so that they give this final result. Don’t update the numbers or the operators.

To achieve this we need to add three pairs of parentheses to our initial calculations. This should look something like this:

``````let result = (...) / (...);
let result2 = 100 / (...);
``````

You don’t need to change the numbers or operators. Just add the parentheses.

I hope this gives you enough hints to improve your code. It’s a pretty tricky one, so don’t get discouraged. You can do it. Okay, in reference to 2, I applied the corrections you mentioned and now I am having errors in my whole code,

Thanks

You made some great progress here. There isn’t much left to make it work:

• The `toFixed()` function doesn’t change the number directly but returns the newly formatted number. Therefore you have to do it like this: `const finalResult = result.toFixed(2);` See how I also added `2` as a parameter? Without a parameter `toFixed()` returns an integer but we want two decimal places.
• You get the error because you didn’t assign the result of the number conversion to a new variable `finalNumber`. This line should look like this: `const finalNumber = Number(finalResult);`. We put `finalResult` in and it will get converted to a number and assigned to `finalNumber`.

I think it should work with this corrections. If you need more help or have some question, just come back. Until then,
Michael

1 Like

I will make the change and take it from there.

Appreciate the help.

1 Like