Some really simple js code is not working
I'm making a programming language adviser, and when i just started, it isn't working. What is wrong with it? Thanks!
Voters
isaiah08 (63)
I changed it, but it still isn't working. @Coder100
Coder100 (17122)
well yeah, you passed in strings as your functions silly! @isaiah08
Coder100 (17122)
@isaiah08 correct code is:
a.onclick = a1;
b.onclick = a1;
angrydoge (465)
You put function a1 {} instead of function ai() {}
JasonLiu19 (69)
uhh for html maybe just do:
<p id="prompt">Hi! I'm Walt, your programming language adviser. Before we begin, have you learned a programming language before?</p>
<button id="a" onclick="a1">Yes!</button>
<button id="b" onclick="b1">No, I'm totally new!</button>
inside a1 js:
document.getElementById('prompt').innerHTML="That's great! What one is it?";
document.getElementById('a').innerHTML="Python";
document.getElementById('b').innerHTML="Java";
document.createElement("button").id="c';
document.getElementById('c').innerHTML="Javascript";
document.createElement("button").id="d';
document.getElementById('d').innerHTML="C++";
Try that.
JasonLiu19 (69)
@JasonLiu19 also make sure to define b1
.
JasonLiu19 (69)
@JasonLiu19 also add paretheses like these:"a1()"
and a1(){
JasonLiu19 (69)
@JasonLiu19 the one for JS and Cpp don't work, so remove those for now.
SixBeeps (5067)
You need () after your function name
Solution
All of your code seems fine. but the tiny error you have is, you forgot the
()
while defining your function. here's the code. you can copy, and paste this:so that way you are defining it properly. for every function it is like that.
That should work
I changed it, but it still isn't working. @RYANTADIPARTHI
@isaiah08 it does work, you have no errors, but if you mean by the buttons, you need to get a, b in your element.
What do you mean a, b in your element? @RYANTADIPARTHI
@isaiah08 sorry, in your onclick, you have to use the functions. like this. copy, and paste it:
[email protected]
@isaiah08 np :)