Calculator implementation in Javascript