+ 3

Error: [variable] is not defined

function diceNum(n) { rect = document.getElementsByTagName("rect"); //rect.length == 9; if (n == 1) { for (x = 0; x < rect.length; x++) { if (x == 4) {rect[x].style.fill = "black"} else {rect[x].style.fill = "white";} } } if (n == 2) { for (x = 0; x < rect.length; x++) { if (x == 2 || x == 6) {rect[x].style.fill = "black";} else {rect[x].style.fill = "white";} } if (n == 3) { for (x = 0; x < rect.length; x++) { if (x == 2 || x == 4 || x == 6) {rect[x].style.fill = "black";} else {rect[x].style.fill = "white";} } } } //output n is not defined line: 'if (n == 1) {'

4th Oct 2016, 3:52 PM
Sjoerd Flameling
Sjoerd Flameling - avatar
6 odpowiedzi
+ 3
yes, or just: var n;
19th Nov 2016, 9:41 PM
Sjoerd Flameling
Sjoerd Flameling - avatar
+ 2
oh, thank you
4th Oct 2016, 7:38 PM
Sjoerd Flameling
Sjoerd Flameling - avatar
+ 2
it's just a part of my code.
30th Oct 2016, 5:03 PM
Sjoerd Flameling
Sjoerd Flameling - avatar
0
It's become variable 'n' dose not exist on the code but only in the function 'diceNum', but i think the first '}' is miss placed in your code.
4th Oct 2016, 6:04 PM
Thomas Hj
Thomas Hj - avatar
0
n can be used only in the function if you wanna use it out of it you have to return it , and something else why you declare a function while you didn't use it?
21st Oct 2016, 10:33 AM
mohammad reza namdari
0
if you want to avoid "not defined problèms" or use and modify à variable in a function without having to systematicaly have go return it, you can déclaré it outside of your function with a null value for exemple. For exemple : Var n = null; function myfunction(){ n = 10; n++; } myfunction () console.log(n) This code wil print in thé console 11
18th Nov 2016, 4:12 PM
Beau Antony
Beau Antony - avatar