You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

<html><body><pre><script>
function calc_surface_carre(c) {
return c*c;
}
function calc_surface_rond(r) {
return r*r*Math.PI;
}
function calculer_surface(dim, type="carre") {
var resultat = 0;
if(type == "rond") {
resultat = calc_surface_rond(dim[0]);
}
else if(type == "carre") {
resultat = calc_surface_carre(dim[0]);
}
else {
document.write(" je ne sais pas faire un " + type);
}
return(resultat);
}
document.write("calculer la surface d'un carré de côté 5 \n");
document.write(calculer_surface([5]));
document.write("\ncalculer la surface d'un rond de rayon 5 \n");
document.write(calculer_surface([5],"rond"));
document.write("\ncalculer la surface d'un rectangle de 3*4 \n");
document.write(calculer_surface([3,4],"rectangle"));
document.write("calculer la surface d'un carré de côté 5 \n");
document.write(calculer_surface([5]));
console.log(resultat);
</script></pre><body></html>