+ 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) {'
6 odpowiedzi
+ 3
yes, or just:
var n;
+ 2
oh, thank you
+ 2
it's just a part of my code.
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.
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?
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