Bonjour à tous,
Je suis en train de faire un code pour gérer des polynomes de deuxième degré. Avec le site http://codeboot.org/, je suis la trace du programme et je réalise qu'il plante lorsqu'il rentre dans la première itération de prototype, i.e. à Polynome.prototye.determinant.
Je suis un peu confus... j'ai essayé divers methode, avec this ou sans this, en nommant une variable x = this.determinant, etc
est-ce que quelqu'un aurait la gentillesse de m'expliquer ce qui se passe?
Merci
Christian
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 var Polynome = function (a, b, c){ if ((a===undefined) && (a!== typeOf(number))) a = 0; if ((b===undefined) && (b!== typeOf(number))) b = 0; if ((c===undefined) && (c!== typeOf(number))) c = 0; this.a = a; this.b = b; this.c = c; this.racine = 0; var determin = this.determinant(this.a, this.b, this.c); this.racine() }; // methode interne Polynome.prototye.determinant = function(a, b, c) { return (Math.sqrt((this.b*this.b)-(4*this.a*this.c))) } // methode interne Polynome.prototye.racine = function(){ if (this.determinant()>0) { this.racinePos(); this.racineNeg(); } else { return ("Ce polynome n'a pas de racine"); } } // methode interne Polynome.prototye.racinePos = function() { return ((-this.b+(this.determinant))/2*this.a); ++this.racine; } // methode interne Polynome.prototye.racineNeg = function() { return ((-this.b-(this.determinant))/2*this.a); ++this.racine; } // methode interne Polynome.prototye.getRacine = function() { if (this.determinant===undefined) return ("Ce polynome n'a pas de racines réelles"); return(this.racine) } Polynome.prototye.toString = function(){ return("f(x)=" + this.a + "x2" + this.b + "x" + this.c + "# de racine" + this.racine); }
Partager