1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title> calculatrice </title>
<script type="text/javascript">
function resultat()
{
var x = 0;
x= eval(calculatrice.affiche.value);
calculatrice.affiche.value = x;
}
var x = prompt("Premier chiffre?");
var y = prompt("Second chiffre?");
if (y==0) {
alert ("division par 0 impossible");
}else{
var z = x/y;
alert(x+'/'+y+'='+z);
}
function ajouter (signe)
{
calculatrice.affiche.value =
calculatrice.affiche.value + signe;
}
</script>
</head>
<body>
<form id="calculatrice" action="javascript" method="post">
<table border="1">
<tr>
<td> <input name="affiche" size="15" maxlength="15"/> </td>
</tr>
</table>
<table border="1">
<tr>
<td> <input type="button" value="7" onclick="ajouter('7')"/> </td>
<td> <input type="button" value="8" onclick="ajouter('8')"/> </td>
<td> <input type="button" value="9" onclick="ajouter('9')"/> </td>
<td> <input type="button" value="+" onclick="ajouter('+')"/> </td>
</tr>
<tr>
<td> <input type="button" value="4" onclick="ajouter('4')"/> </td>
<td> <input type="button" value="5" onclick="ajouter('5')"/> </td>
<td> <input type="button" value="6" onclick="ajouter('6')"/> </td>
<td> <input type="button" value="-" onclick="ajouter('-')"/> </td>
</tr>
<tr>
<td> <input type="button" value="1" onclick="ajouter('1')"/> </td>
<td> <input type="button" value="2" onclick="ajouter('2')"/> </td>
<td> <input type="button" value="3" onclick="ajouter('3')"/> </td>
<td> <input type="button" value="*" onclick="ajouter('*')"/> </td>
</tr>
<tr>
<td> <input type="button" value="=" onclick="resultat()"/> </td>
<td> <input type="button" value="0" onclick="ajouter('0')"/> </td>
<td> <input type="button" value="/" onclick="ajouter('/')"/> </td>
</tr>
<tr>
<td> <input type="reset" value="C"/> </td>
</tr>
</table>
</form>
</body>
</html> |
Partager