-
Lenguaje
JavaScript
-
Descripción
Hacer un algoritmo que ingrese una cantidad en horas y una cantidad en minutos. Luego, convertir su equivalente del tiempo en segundos.
Validar que las horas ingresadas esté en el rango 0..23 y los minutos en el rango 0..59. En caso contrario, mostrar un error.
El algoritmo debe mostrar el tiempo expresado en segundos.
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Equivalente de horas y minutos en segundos</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
<html>
<head>
<title>Equivalente de horas y minutos en segundos</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
function algoritmo()
{
let horas, minutos, segundos;
horas = parseInt (document.formulario1.horas.value);
minutos = parseInt (document.formulario1.minutos.value);
if(horas>=0&&horas<24&&minutos>=0&&minutos<60)
segundos=(horas*60+minutos)*60;
else
{
segundos=0;
alert('Un error');
}
document.formulario1.segundos.value = segundos;
}
{
let horas, minutos, segundos;
horas = parseInt (document.formulario1.horas.value);
minutos = parseInt (document.formulario1.minutos.value);
if(horas>=0&&horas<24&&minutos>=0&&minutos<60)
segundos=(horas*60+minutos)*60;
else
{
segundos=0;
alert('Un error');
}
document.formulario1.segundos.value = segundos;
}
</script>
</head>
<body>
<form name="formulario1">
<table style="text-align: left; margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td>
<label for="horas">Ingresa el valor de horas:</label>
</td>
<td>
<input name="horas" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="minutos">Ingresa el valor de minutos:</label>
</td>
<td>
<input name="minutos" required="required" step="1" type="number" />
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="button" onclick="algoritmo();" />
<input type="reset" />
</td>
</tr>
<tr>
<td>
<label for="segundos">Valor de segundos:</label>
</td>
<td>
<input name="segundos" step="1" type="number" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
</head>
<body>
<form name="formulario1">
<table style="text-align: left; margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td>
<label for="horas">Ingresa el valor de horas:</label>
</td>
<td>
<input name="horas" required="required" step="1" type="number" />
</td>
</tr>
<tr>
<td>
<label for="minutos">Ingresa el valor de minutos:</label>
</td>
<td>
<input name="minutos" required="required" step="1" type="number" />
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="button" onclick="algoritmo();" />
<input type="reset" />
</td>
</tr>
<tr>
<td>
<label for="segundos">Valor de segundos:</label>
</td>
<td>
<input name="segundos" step="1" type="number" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>