Skip to content

Commit

Permalink
Merge pull request #5376 from alexgarcia1907/retos/reto#40/javascript
Browse files Browse the repository at this point in the history
Reto #40 - javascript
  • Loading branch information
Roswell468 authored Oct 16, 2023
2 parents 1492c27 + a81195d commit 7e7f57e
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const prompt = require("prompt-sync")();

// Ask and validate whether is a number
function askAndValidateNumber() {
let number = parseInt(prompt("Ingrese un valor para imprimir su tabla de multiplicar del 1 hasta el 10: "));

if (typeof number === 'number' && !isNaN(number)) {
generateMultiplicationTable(number);
} else {
console.log("Debes ingresar un numero.")
}
}

// Generate multiplication table for entered number
function generateMultiplicationTable(number) {
for (let i = 1; i <= 10; i++) {
let multiplicationResult = number * i
console.log(`${number} x ${i} = ${multiplicationResult}`)
}
}

askAndValidateNumber()

0 comments on commit 7e7f57e

Please sign in to comment.