Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  87] [ 3]  / answers: 1 / hits: 25849  / 6 Years ago, wed, july 11, 2018, 12:00:00

I'm pretty new to Javascript and playing around with it at the moment. However, I can't actually test my code because I get the following error:



Uncaught TypeError: namecaller is not a function
at HTMLButtonElement.onclick (Tools.html:101)


Here is my code:



div id=content>
<script>
function namecaller(){
var a = scurvy;
var b = dog;
document.getElementById(namecaller).innerHTML = You are a + a + + b;
}
</script>
Namecaller</p>
<button type=button onclick=namecaller()>
You are a...</button>


I have no clue why it doesn't work, looked at other StackOverflow questions and also at the W3 tutorials.


More From » html

 Answers
36



function namecaller() {
var a = scurvy;
var b = dog;
document.getElementById(content).innerHTML = You are a + a + + b;
}

<div id=content></div>
<button type=button onclick=namecaller()>
You are a...</button>





The code seems to have a lot of problems like your tags were not in properly written. The tags need to open closed properly. And your script should be in right place so that it gets compiled. Then you have not given an id to any of the elements and try calling them. So here is the working example of how the code should be properly written for bug-free compilation.


[#54008] Friday, July 6, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;