Bonjour à tous,
Je dois réaliser un projet en javascript or j'ai une erreur qui me bloque.
On me dit que mon tableau nommé global n'est pas défini quand je l'appelle dans une fonction.
Vous auriez une idée ??
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
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
88
89
90
91
92
93
94
95
96
97
98
99
100 var global = new Array(); var nbCase = window.prompt("Entrez le nombre de cases que vous voulez pour votre tableau"); var test=nbCase*nbCase; function TBL_virtuel() { for (var x=0; x<nbCase; x++) { global[x] = new Array(); for (var y=0; y<nbCase; y++) { global[x][y]="vide"; } } return global; } function afficher() { var p=0; var coef=0.80; var nombreAs = nbCase*coef; var cellules = document.getElementsByTagName('td'); for (var x=0; x<nbCase; x++) { for (var y=0; y<nbCase; y++) { calcul_place_A(global); calcul_place_B(); } } } function calcul_place_A () { var p=0; var nombreAs = test/8.1; Math.round(nombreAs); do { var aleatoire = Math.random(); var aleatoi = Math.random(); var placeX = Math.round(aleatoire * nbCase); var placeY = Math.round(aleatoi * nbCase); if ((placeX>0) && (placeX<=nbCase) && (placeY>0) && (placeY<=nbCase)) { global[placeX][placeY]="As"; alert (global[placeX][placeY]); } p++; } while (p<nombreAs); //document.write(global); return global; } function calcul_place_B () { if ((x>0)&&(y>0)&&(global[x-1][y-1]!="As")) { global[x-1][y-1]++; } if ((x>0)&&(y>0)&&(global[x][y-1]!="As")) { global[x][y-1]++; } if ((x<nbCase-1)&&(y>0)&&(global[x+1][y-1]!="As")) { global[x+1][y-1]++; } if ((x>0)&&(y>0)&&(global[x-1][y]!="As")) { global[x-1][y]++; } if ((x>0)&&(y>0)&&( global[x][y]!="As")) { global[x][y]++; } if ((x<nbCase-1)&&(y>0)&&(global[x+1][y]!="As")) { global[x+1][y]++; } if ((x>0)&&(y<nbCase-1)&&(global[x-1][y+1]!="As")) { global[x-1][y+1]++;vivant++; } if ((x>0)&&(y<nbCase-1)&&(global[x][y+1]!="As")) { global[x][y+1]++; } if ((x<nbCase-1)&&(y<nbCase-1)&&(global[x+1][y+1]!="As")) { global[x+1][y+1]++; } document.write(global); }







Répondre avec citation






de déclarations variables qui se baladent à droite et à gauche. Déclare tes variables au début de tes fonctions, tu gagneras en lisibilité et sans doute en performance.

Partager