From cd648685e1390823cdc31989fee192f2cbc7a17d Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Wed, 9 Feb 2022 14:49:55 -0500 Subject: [PATCH] stricter syntax --- index.js | 70 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/index.js b/index.js index 29a01de..5d22dbe 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,29 @@ const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout -}) +}); function dec_to_base() { readline.question(`Enter a number to convert: `, num => { - num = parseInt(num) + num = parseInt(num); readline.question(`Enter a number new base: `, base => { - base = parseInt(base) + base = parseInt(base); try { - new_num = num.toString(base) + new_num = num.toString(base); console.log(`\nBASE 10: ${num} ==> BASE ${base}: ${new_num}`); } catch (RangeError) { console.log(`Base is not in the range of 2 to 36.\nExiting...`); } finally { - readline.close() - } - }) - }) -} + readline.close(); + }; + }); + }); +}; function base_to_dec() { readline.question(`Enter a number to convert: `, num => { readline.question(`Enter the number's base: `, base => { - base = parseInt(base) + base = parseInt(base); try { new_num = parseInt(num, base); console.log(`\nBASE ${base}: ${num} ==> BASE 10: ${new_num}`); @@ -31,53 +31,53 @@ function base_to_dec() { console.log(`Base is not in the range of 2 to 36.\nExiting...`); } finally { - readline.close() - } - }) - }) -} + readline.close(); + }; + }); + }); +}; function base_to_base() { readline.question(`Enter a number to convert: `, num => { readline.question(`Enter the number's base: `, base => { - base = parseInt(base) + base = parseInt(base); readline.question(`Enter a number new base: `, new_base => { - new_base = parseInt(new_base) + new_base = parseInt(new_base); try { - dec_num = parseInt(num, base); - new_num = dec_num.toString(new_base) + let dec_num = parseInt(num, base); + let new_num = dec_num.toString(new_base); console.log(`\nBASE ${base}: ${num} ==> BASE ${new_base}: ${new_num}`); } catch (RangeError) { console.log(`One or more bases is not in the range of 2 to 36.\nExiting...`); } finally { - readline.close() - } - }) - }) - }) -} + readline.close(); + }; + }); + }); + }); +}; readline.question(`Choose an option:\n\n1) decimal to any base\n2) any base to decimal\n3) any base to any base\n`, choice => { if (choice * 1.0) { choice = parseInt(choice); switch (choice) { case 1: - dec_to_base() + dec_to_base(); break; case 2: - base_to_dec() + base_to_dec(); break; case 3: - base_to_base() + base_to_base(); break; default: - console.log("Please choose a proper entry.") - readline.close() + console.log("Please choose a proper entry."); + readline.close(); break; - } + }; } else { - console.log("Please enter a number.") - readline.close() - } -}) \ No newline at end of file + console.log("Please enter a number."); + readline.close(); + }; +}); \ No newline at end of file