Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Js math is broken

Hi I don’t understand that. output should be £112 but it’s £1696 because it adds 16 and next to it 96.

let output = 2
let cal = "£" + output * 8 + 96
console.log(cal)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you start your expression with a string, the + operator is used to concatenate. Try using parentheses:

let output = 2
let cal = "£" + (output * 8 + 96)

It’s also nice to use template syntax:

let cal = `£${output * 8 + 96}`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading