#!/usr/bin/env node; /****************************************************************************** * This program demonstrates how to prompt the user for input. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ const Utils = require('./Utils'); const main = async () => { let favoriteInt = 0; let favoriteLong = 0; let favoriteDouble = 0.0; try { const FAVORITE_INT_INPUT = await Utils.prompt("What is your favorite small integer? "); favoriteInt = Utils.stoi(FAVORITE_INT_INPUT); const FAVORITE_LONG_INPUT = await Utils.prompt("What is your favorite large integer? "); favoriteLong = Utils.stoi(FAVORITE_LONG_INPUT); const FAVORITE_DOUBLE_INPUT = await Utils.prompt("What is your favorite floating point? "); favoriteDouble = Utils.stod(FAVORITE_DOUBLE_INPUT); } catch (ex) { if (ex instanceof Utils.NumberFormatError) { console.log(["Bad input! ", String(ex)].join('')); } else if (ex instanceof Error) { console.log("Don't know what went wrong!"); } } const SUM = favoriteInt + favoriteLong + favoriteDouble; console.log(Utils.format("All together they add up to {0:f}!", SUM)); } main().catch( e => { console.error(e) } );