Last active
March 8, 2022 13:54
-
-
Save 0xAliRaza/e2c74fdfed75292ec08e0fe7adacd3e9 to your computer and use it in GitHub Desktop.
Print math table of given parameter in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Date: 08/03/2022 | |
* Task: 04 | |
* Author: Ali Raza ([email protected]) | |
* | |
*/ | |
function printTable(num) { | |
// Check if a valid number | |
if (!Number.isInteger(num)) { | |
console.error("Please provide a valid number."); | |
return; | |
} | |
if (num <= 0) { | |
console.error("Provided number should be greater than zero."); | |
return; | |
} | |
const table = {}; | |
// Fill all the table values in key=>value pairs | |
for (let i = 1; i <= 10; i++) { | |
table[`${num} x ${i}`] = +Number(num * i).toFixed(1); | |
} | |
console.table(table); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment