Calculatrice javascript
onizuka
-
Utilisateur anonyme -
Utilisateur anonyme -
J'ai créer une calculatrice sur javascript.
J'ai effectuer des tests sur la calculatrice elle fonctionne dans tout les cas sauf pour :
Addition et Multiplication exemple : 5+5*3=30 elle me donne le résultat de 20.
Addition et Division exemple : 10+5*4=60 elle me donne le résultat de 30.
Soustraction et Multiplication exemple : 20-4*2=32 elle me donne le résultat de 12.
Soustraction et Division exemple : 30-6/4=6 elle me donne le résultat de 28.5.
Je vous met mon code html et javascript :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="calculatrice.js"></script>
</head>
<form name="calculatrice">
<table border="3" cellpadding="8" width="15%">
<tr>
<td align="center" colspan="3">
<input type="text" size="30" maxlength="30" name="affichage"> <td>
<input type="button" value="C" onclick="Supprim()"></td>
</tr>
<tr>
<td align="center" width="25%">
<input type="button" value="7" onclick="Ajout('7')"></td>
<td align="center" width="25%">
<input type="button" value="8" onclick="Ajout('8')"></td>
<td align="center" width="25%">
<input type="button" value="9" onclick="Ajout('9')"></td>
<td align="center" width="25%">
<input type="button" value="+" onclick="Ajout('+')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="4" onclick="Ajout('4')"></td>
<td align="center" width="25%">
<input type="button" value="5" onclick="Ajout('5')"></td>
<td align="center" width="25%">
<input type="button" value="6" onclick="Ajout('6')"></td>
<td align="center" width="25%">
<input type="button" value="-" onclick="Ajout('-')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="1" onclick="Ajout('1')"></td>
<td align="center" width="25%">
<input type="button" value="2" onclick="Ajout('2')"></td>
<td align="center" width="25%">
<input type="button" value="3" onclick="Ajout('3')"> </td>
<td align="center" width="25%">
<input type="button" value="*" onclick="Ajout('*')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="0" onclick="Ajout('0')"></td>
<td align="center" width="25%">
<input type="button" value="." onclick="Ajout('.')"></td>
<td align="center" width="25%">
<input type="button" value="=" onclick="Resultat()"></td>
<td align="center" width="25%">
<input type="button" value="/" onclick="Ajout('/')"></td>
<tr/>
</table>
</form>
</html>
Javascript
function Resultat()
{
document.calculatrice.affichage.value = eval(document.calculatrice.affichage.value)
}
function Supprim()
{
document.calculatrice.affichage.value = ""
}
function Ajout(Signe)
{
document.calculatrice.affichage.value += Signe
}
Quelqu'un peut-il m'aider svp ?
J'ai effectuer des tests sur la calculatrice elle fonctionne dans tout les cas sauf pour :
Addition et Multiplication exemple : 5+5*3=30 elle me donne le résultat de 20.
Addition et Division exemple : 10+5*4=60 elle me donne le résultat de 30.
Soustraction et Multiplication exemple : 20-4*2=32 elle me donne le résultat de 12.
Soustraction et Division exemple : 30-6/4=6 elle me donne le résultat de 28.5.
Je vous met mon code html et javascript :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="calculatrice.js"></script>
</head>
<form name="calculatrice">
<table border="3" cellpadding="8" width="15%">
<tr>
<td align="center" colspan="3">
<input type="text" size="30" maxlength="30" name="affichage"> <td>
<input type="button" value="C" onclick="Supprim()"></td>
</tr>
<tr>
<td align="center" width="25%">
<input type="button" value="7" onclick="Ajout('7')"></td>
<td align="center" width="25%">
<input type="button" value="8" onclick="Ajout('8')"></td>
<td align="center" width="25%">
<input type="button" value="9" onclick="Ajout('9')"></td>
<td align="center" width="25%">
<input type="button" value="+" onclick="Ajout('+')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="4" onclick="Ajout('4')"></td>
<td align="center" width="25%">
<input type="button" value="5" onclick="Ajout('5')"></td>
<td align="center" width="25%">
<input type="button" value="6" onclick="Ajout('6')"></td>
<td align="center" width="25%">
<input type="button" value="-" onclick="Ajout('-')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="1" onclick="Ajout('1')"></td>
<td align="center" width="25%">
<input type="button" value="2" onclick="Ajout('2')"></td>
<td align="center" width="25%">
<input type="button" value="3" onclick="Ajout('3')"> </td>
<td align="center" width="25%">
<input type="button" value="*" onclick="Ajout('*')"></td>
<tr/>
<tr>
<td align="center" width="25%">
<input type="button" value="0" onclick="Ajout('0')"></td>
<td align="center" width="25%">
<input type="button" value="." onclick="Ajout('.')"></td>
<td align="center" width="25%">
<input type="button" value="=" onclick="Resultat()"></td>
<td align="center" width="25%">
<input type="button" value="/" onclick="Ajout('/')"></td>
<tr/>
</table>
</form>
</html>
Javascript
function Resultat()
{
document.calculatrice.affichage.value = eval(document.calculatrice.affichage.value)
}
function Supprim()
{
document.calculatrice.affichage.value = ""
}
function Ajout(Signe)
{
document.calculatrice.affichage.value += Signe
}
Quelqu'un peut-il m'aider svp ?
A voir également:
- Calculatrice javascript
- Calculatrice gratuit - Télécharger - Calcul & Conversion
- Installation calculatrice - Télécharger - Calcul & Conversion
- Telecharger javascript - Télécharger - Langages
- Ma-calculatrice - Télécharger - Calcul & Conversion
- Calculatrice windows 7 - Télécharger - Calcul & Conversion
1 réponse
Bonjour
Ta calculatrice semble bien fonctionner. Je ne vois pas ce qu'il y a à corriger.
Suivant les règles habituelles de l'évaluation des expressions, on effectue les multiplications et les divisions avant les additions et les soustractions donc par exemple :
5+5*3 = 5 + 15 = 20 et non pas 30
30-6/4 = 30 - 1.5 = 28.5 et non pas 6
C'est l'habitude aussi bien chez les mathématiciens que dans les langages informatiques. Si tu veux forcer un ordre d'évaluation différent, il faut utiliser des parenthèses :
(5+5)*3 = 10 * 3 =30
(30-6)/4 = 24 / 4 = 6
Ta calculatrice semble bien fonctionner. Je ne vois pas ce qu'il y a à corriger.
Suivant les règles habituelles de l'évaluation des expressions, on effectue les multiplications et les divisions avant les additions et les soustractions donc par exemple :
5+5*3 = 5 + 15 = 20 et non pas 30
30-6/4 = 30 - 1.5 = 28.5 et non pas 6
C'est l'habitude aussi bien chez les mathématiciens que dans les langages informatiques. Si tu veux forcer un ordre d'évaluation différent, il faut utiliser des parenthèses :
(5+5)*3 = 10 * 3 =30
(30-6)/4 = 24 / 4 = 6