ingresar, mostrar, incrementar y duplicar numero
JavaScript
Publicado el 9 de Mayo del 2018 por Elias
3.363 visualizaciones desde el 9 de Mayo del 2018
Ejercicio ingreso de numero, mostrar, incrementar y duplicar mediante funciones.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ejercicio 4 Operaciones sobre un Imput</title>
</head>
<body>
<input type="text" id="idCampo" onclick="pedirValor()" />
<button id="mostrar" onclick="mostrarValor()" >Mostrar valor</button>
<button id="sumar" onclick="incremento()">Suma 1</button>
<button id="duplica" onclick="multiplicar()">Duplica</button>
</body>
<script>
function pedirValor(){
var ingreso = prompt("Ingrese un valor: ");
document.getElementById("idCampo").value = ingreso;
}
function mostrarValor(){
var valor = document.getElementById("idCampo").value;
alert(valor);
}
function incremento(){
var incre = parseInt(document.getElementById("idCampo").value);
document.getElementById("idCampo").value = incre += 1;
}
function multiplicar(){
var multi = parseInt(document.getElementById("idCampo").value);
document.getElementById("idCampo").value = multi * 2;
}
</script>
</html>
Comentarios sobre la versión: 1.0 (2)