BasesWeb/FRONTEND/JavascriptExo2.html

37 lines
736 B
HTML
Raw Normal View History

2022-12-01 15:46:05 +01:00
<!DOCTYPE,html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JavascriptExo2</title>
<script type="text/javascript">
function somme(compter) {
var i=1
var somme=0;
if (i<=0)
{
alert("Veuillez saisir un entier positif non nul.")
}
else
{
somme=i;
document.write("Pour i = "+i+"--> somme = "+somme+"<br/>")
while(i<compter)
{
i=i+1;
somme=somme+i;
document.write("\n"+"Pour i = "+i+"--> somme = "+somme+"<br/>");
}
}
}
</script>
</head>
<body>
<script type="text/javascript">
var compter=0;
compter=prompt("Donnez moi un entier positif non nul: ", "");
somme(compter);
</script>
</body>
</html>