Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
174 views

Exercices Javascript PDF

The document contains code for 4 JavaScript programs: 1. A cube calculator that takes a number input and displays its cube 2. A program that takes 2 number inputs and displays the maximum 3. A program that takes a number input, checks if it is numeric, and if so displays its square 4. A program that uses a switch statement to determine the number of days in a given month and year based on user inputs

Uploaded by

elouadil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views

Exercices Javascript PDF

The document contains code for 4 JavaScript programs: 1. A cube calculator that takes a number input and displays its cube 2. A program that takes 2 number inputs and displays the maximum 3. A program that takes a number input, checks if it is numeric, and if so displays its square 4. A program that uses a switch statement to determine the number of days in a given month and year based on user inputs

Uploaded by

elouadil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Le cube

<html> <head> <title>cube</title> <script language="javascript"> function cube() { r=document.formulaire.saisir.value* document.formulaire.saisir.value*document.fo rmulaire.saisir.value; alert("le cube de "+document.formulaire.saisir.value+"="+r); } </script> </head> <body> <form name="formulaire"> <input type="text" size="2" name="saisir"> <input type= "button" value="calcul de cube" onclick="cube()"> </body> </html>

Maximum des deux entiers <html> <head> <title> maximale</title> </head> <body> <script language="javascript"> var a=window.prompt("a= ","0"); var b=window.prompt("b= ","0"); a=Number(a); b=Number(b); if (a>b) m=a; else m=b; document.write("le maximum est : "+m); </script> </body> </html>

Test dune valeur <html> <head> <title>test</title> </head> <body> <script language="javascript"> var a= window.prompt("la valeur "); if (isNaN(a)) alert("conversion impossible"); else { a=Number(a); c=a*a; alert("le carr de " +a+"= "+c); } </script> </body> </html>

Tp3 : les structures de controles Exercice1 Jours

<html> <head> <title> jours</title> </head> <body> <script language="javascript"> var m=window.prompt("mois","1"); var a=window.prompt("ann","2008"); switch(m) { case"1":case"3":case"5":case"7":case"8":c ase"10":case"12":j=31;break; case"4":case"6":case"9":case"11":j=30;bre ak; case"2": if(a%4==0) j=29;else j=28;break; } alert(" les jours du mois"+m+" de lann"+a+"="+j);

</script> </body> </html> Exercice2 : Produit

<html> <head> <title> ggg</title> </head> <body> <script language="javascript"> var a= Number(window.prompt("lavaleur de a","1")); var b= Number(window.prompt("lavaleur de b","1")); s=0; for (i=1;i<=b;i++) s+=a; alert(a+"*"+b+"="+s); </script> </body> </html>

Exercice3 Somme <html> <head> <title>somme</title> </head> <body> <script language="javascript"> do { var n=window.prompt("n= "); } while(n<=0); s=0; for (i=1;i<=n;i++) s+=i; alert("la sommes des "+n+" premiers entiers = "+s); </script> </html> </html>

Exercice3 PGCD <html> <head> <title>PGCD</title> </head> <script language="javascript"> function pgcd(a,b) { while(a!=b) { if(a>b) a=a-b; else b=b-a; } return(a); } </script> <body> <script language="javascript"> do { var n= window.prompt("la valeur de n= "); var m= window.prompt("la valeur de m= ");

} while (n<0||m<0); var k=pgcd(n,m) alert("le PGCD=" +k); </script> </body> </html>

You might also like