DEV Community

loading...

Discussion on: How to create a calculator application with Ionic framework 3 by using Ionic Creator for UI

Collapse
imranyouthink profile image
Lucien Zera

when the number ends with an operator like "+" or "-" it will shown an error that says "Unexpected end of input" - How to fix this?

Collapse
nikola profile image
Nikola Brežnjak Author

It's actually quite easy (just wrap it in try/catch block) and I already covered it in the post #3 that should be done by the end of the week (I'll update you once it's done). But, until then, here the example code you can use:

try {
    this.result = eval(this.result).toFixed(2);
} catch () {
    // this.showAlert(); //show some error message
}
Collapse
imranyouthink profile image
Lucien Zera

Thank you very much!

Thread Thread
nikola profile image
Nikola Brežnjak Author • Edited

Hey Lucien,

You're welcome! The new post in the series should be out tomorrow, where you'll see this implemented 💪