-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo.js
More file actions
36 lines (34 loc) · 1010 Bytes
/
codigo.js
File metadata and controls
36 lines (34 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// ========================================
// Código JavaScript
// TABLA DE MULTIPLICAR
// (cc) 3con14.pro
// ========================================
var resultado = document.getElementById('resultado');
function TablaMultiplicar(){
var n = document.getElementById('dato').value;
var m;
var tabla = '';
if (isNaN(n) || n === '') {
tabla = '¡¡ Error !! >>> Dato mal escrito.';
resultado.style.backgroundColor = '#f00';
} else {
tabla = '<table>';
resultado.style.backgroundColor = 'inherit';
n = parseInt(n);
m = n+9;
tabla += '<tr><td></td>';
for (var k=1; k<=10;k++) {
tabla += '<td>' + k + '</td>';
}
tabla += '</tr>';
for (var i=n;i<=m;i++) {
tabla += '<tr><td>'+ i +'</td>';
for (var j=1; j<=10;j++){
tabla += '<td data-n="'+ i +'x'+ j +'=' + (i*j) +'">' + (i*j) + '</td>';
}
tabla += '</tr>';
}
tabla += '</tabla>';
}
resultado.innerHTML = tabla;
}