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

The program keeps doing other if statements

I’m building a calculator application, and when I want to use another mathematical expression, it doesn’t work. I want to do subtraction, and it does addition, as if the program didn’t see other if statements.

function Output(a) {
    window.alert(a)
    }
expression = window.prompt("what expression do you want to use? addition/subtraction/multiplication or divison");
if (expression = "addition") {
    additionValue1 = window.prompt("Value1: ");
    additionValue2 = window.prompt("Value2: ");
    Output(parseInt(additionValue1, 10) + parseInt(additionValue2, 10));
}
if (expression = "subtraction") {
    subtractionValue1 = window.prompt("Value1: ");
    subtractionValue2 = window.prompt("Value2: ");
    Output(parseInt(subtractionValue1, 10) - parseInt(subtractionValue2, 10));
}
if (expression = "multiplication") {
    multiplicationValue1 = window.prompt("Value1: ");
    multiplicationValue2 = window.prompt("Value2: ");
    Output(parseInt(multiplicationValue1, 10) * parseInt(multiplicationValue2, 10));
}
if (expression = "divison") {
    divisionValue1 = window.prompt("Value1: ");
    divisionValue2 = window.prompt("Value2: ");
    Output(parseInt(divisionValue1, 10) / parseInt(divisionValue2, 10));
}

Thanks.

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

>Solution :

You should use == or === for comparing values. The single = is for assignment.

if (expression === "addition") { // Do something... }
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