EJERCICIO 1 de la entrega CU01122E del tutorial de programación web con JavaScript desde cero:
function obtenerImporteConImpuestos(importe_sin_impuestos,tipo_producto)
{
var msg='Importe sin impuestos: '+importe_sin_impuestos+'. ';
var imp,res;
switch(tipo_producto){
case 1:
imp=importe_sin_impuestos*0.21;
res=parseInt(importe_sin_impuestos)+parseInt(imp);
alert(msg+'Importe con el impuesto: '+res);
break;
case 2:
imp=importe_sin_impuestos*0.10;
res=parseInt(importe_sin_impuestos)+parseInt(imp);
alert(msg+'Importe con el impuesto: '+res);
break;
case 3:
imp=importe_sin_impuestos*0.5;
res=parseInt(importe_sin_impuestos)+parseInt(imp);
alert(msg+'Importe con el impuesto: '+res);
break;
}
return res;
}
EJERCICIO 2:
function obtenerImporteConImpuestos2(importe_sin_impuestos){
var tipo_producto=0;
var resultado=[];
var msg;
if (tipo_producto==1) {
msg=alert(resultado[1]=importe_sin_impuestos*1.21);
return msg;
}
else if (tipo_producto==2){
msg=alert(resultado[2]=importe_sin_impuestos*1.10);
return resultado[2];
}else if (tipo_producto==3){
msg=alert(resultado[3]=importe_sin_impuestos*1.05);
}else {
msg=alert(resultado[0]);
}
}
Archivo html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Entrega 22</title>
<script type="text/javascript" src="Ejercicio22.js">
</script>
</head>
<body>
<div> <p>Aquí un párrafo de texto situado antes de la imagen, dentro de un div contenedor</p>
<img onclick="obtenerImporteConImpuestos(300000,2)" src="http://i.imgur.com/afC0L.jpg" alt="Notepad++"
title="Notepad++, un útil editor de texto">
<p onclick ="alert('Alerta JavaScript')" style="color: #D2691E;">Aquí otro párrafo de texto.
JavaScript es un lenguaje utilizado para dotar de efectos dinámicos a las páginas web. </p>
<img onclick="obtenerImporteConImpuestos2(100)" src="http://i.imgur.com/afC0L.jpg" alt="Notepad++"
title="Notepad++, un útil editor de texto">
</div>
</body>
</html>