I write my JavaScript correctly, but it still doesn’t work. I feel like a fake. My script matches the solution or it looks like the write syntax but I’m still lost.
Please give your full code so we can guide you.
Hi @camie.cam.codes!
It is normal to get frustrated with JavaScript at times. We would be happy to help you with your issue. Like @codely said we will need to see your code and link to the challenge you are working on.
Here is a JS Bin of my code. https://jsbin.com/jajumaz/12/edit?js,output
The objective is to get the table on the right to populate with State Name, abbreviation, candidate names, and results.
Again my code, as far as I can see, look accuate. But in the console log I’m getting an error stating: My children[0]
can’t be undefined. Or something like that.
Look in the JS console for an error. You have a typo.
fixed it, but still no working table
Hmm, I’m still getting the error and seeing it in your code:
282: var stateAbrev = header.childern[0].children[1];
Changed it
“ReferenceError: state is not defined
at jajumaz.js:130:33”
So, if state is not defined. How do I define it? In a function, like earlier in the script, or as a variable?
stateName.innerText = theStates[state].nameFull;
What is the value of state
supposed to be? An integer? A string? Where are you getting this value from? Are you supposed to be pulling it from some data structure? Are you getting it from the HTML?
state is a variable stated in a third party JavaScript. When I call state
for was called for another method it work, made the states change color when you mouse over them.
So they may have used state
in that third party JS code but in order for you to use it in yours you have to define it and give it the proper value. What value do you intend it to have in your code? And how are you going to give it that value?
I need to use theStates[state]
to define which state I hover over. The directions were to set all my innerText
to variables. But may you are right. I need to redefine that variable in my current script.
The function setStateResults
is called for you in the mouseIn
prototype method and gets passed the id setStateResults(this.id);
.
Here is the method from the library:
State.prototype.mouseIn = function()
{
if ( !this.highlighted )
{
this.renderCount = this.gradientOffset;
setStateResults(this.id);
}
this.highlighted = true;
this.counted = true;
}
So the state
parameter is what was passed into the function, i.e. this.id
You only have access to the state
parameter inside the setStateResults
function, but you are trying to use it outside the function. If you look at the original example code you can see state
is never used outside the function.
Thank you all! Thank you, thank you!