# Expected an Identifer and instead saw 'else'. What should I do?

Problem
The program won’t run, it says “Expected an Identifer and instead saw ‘else’.” I’ve tried everything I know - what should be done?

I’m creating a program where it should prompt the user for the number of pounds to be converted. The program should check if the number of pounds is greater than 0 and a number. If the input is 0 or a negative number or the input is not a number then an error message should be displayed – “input error, please input a number greater than 0”.
If the pounds to be exchanged is > £500 then no commission is charged. If the number of pounds worked is < = £500 then 3% commission is charged.
An output message should be displayed to show the number of euros exchanged.

Program

``````//Set variable
const exchange = 1.19;
var pounds = 0;
var euros = 0.0;

//Using prompt to get value from user
pounds = prompt("Enter the amount of pounds you wish to convert:");
pounds = parseInt(pounds);

//Display amount of euros depending on how much pounds user enters
if (pounds > 0)
{
if (pounds > 500)
euros = (pounds * exchange).toFixed(2);
} else {
euros = (pounds * exchange);
euros = (euros - ((euros / 100) * 3)).toFixed(2);
}
else;
{
}
``````

As an amateur js programmer, any other tips/advice would be much appreciated!

There are no semi-colons in an if statement.

``````if () {

}
else if () {

} else {

}
``````
1 Like
``````//Set variable
const exchange = 1.19;
var pounds = 0;
var euros = 0.0;

//Using prompt to get value from user
pounds = prompt("Enter the amount of pounds you wish to convert:");
pounds = parseInt(pounds);

//Display amount of euros depending on how much pounds user enters
if (pounds > 0)
{
if (pounds > 500)
euros = (pounds * exchange).toFixed(2);
} else {
euros = (pounds * exchange);
euros = (euros - ((euros / 100) * 3)).toFixed(2);
}
else
{
}
``````

I amended it, the program still doesn’t work - also, I’m not using else if statement - this is my design, if it helps.

``````Begin
get pounds
If pounds > 0
If pounds > 500
set  euros to pounds * exchange
display euros
else
set  euros to (pounds * exchange)
set euros to (euros – ((euros/100)*3))
display euros
else
display invalid entry error message
end if
end

``````

It seems odd that there would be no commission for amounts larger than 500. I would interpret that to mean that commisssion is charged on only the first 500 pounds.

``````euros = (pounds - 500) * exchange + 500 * exchange * 0.97

euros = exchange * ((pounds - 500) + 500 * 0.97)
``````

Here’s some trial code…

``````let exchange = 1.19;
let pounds = 1500;    //=> £1500 => €1767.15
//pounds = 500;       //=> £500  => €577.15
//pounds = 100;       //=> £100  => €115.43
if (pounds > 500) {
console.log(`£\${pounds} => €\${+(exchange * ((pounds - 500) + 500 * 0.97)).toFixed(2)}`);
} else if (pounds > 0) {
console.log(`£\${pounds} => €\${+(exchange * pounds * 0.97).toFixed(2)}`);
} else {
console.log("Input error.")
}
``````

https://repl.it/Mj66

1 Like

Any chance you could help me with the issue i have - “Expected an Indentifier and instead saw ‘else’.”?

Hi @ibobbyo,

I have no comment/idea about how your code is structured, but I definitely can help spot the syntax issue.

``````//Display amount of euros depending on how much pounds user enters
if (pounds > 0)
{
if (pounds > 500)  //<=== missing an opening curly bracket for second if
euros = (pounds * exchange).toFixed(2);
} else {
euros = (pounds * exchange);
euros = (euros - ((euros / 100) * 3)).toFixed(2);
}  // <=== closes else
//<=== missing another closing curly bracket for first if
else
{