Skip to content
Sign upLog in
← Back to Community
How to fix "Syntax error, expected expression but got else" in javascript
Profile icon
VMTU

I keep getting this error from my code, I dont know why ive tried to fix it many times but it did not work

if ( d == false ) {
if ( x == false ) {
num1 = 1;
}
else {
num2 = 1;
}
else {
if ( x == false ) {
num1 = num1 + e
e = e * 10
}
else {
num2 = num2 + e
e = e * 10
}
}
}

Voters
Profile icon
VMTU
Comments
hotnewtop
Profile icon
[deleted]

Is this better:

if ( d == false ) { if ( x == false ) { num1 = 1; } else { num2 = 1; } } if ( x == false ) { num1 = num1 + e e = e * 10 } else { num2 = num2 + e e = e * 10 }
Profile icon
VMTU

this gave me "expected expression, got }"

Profile icon
[deleted]

@VMTU
Could you share a link to your repl thanks.

Profile icon
VMTU

Ok

Profile icon
VMTU
Profile icon
[deleted]

@VMTU
I have looked at your code, forked it and made a few changes. Have a look and see if it is helpful: https://repl.it/@malvoliothegood/MULTI-CALC#index.html

Profile icon
VMTU

Thank you!

Profile icon
DJWang

What language is this?

Profile icon
VMTU

javascript

Profile icon
DJWang