+ 1

Javascript onclick

Could anyone please explain what I am doing wrong here? <button onclick="add()"> Add Item </button>

24th Aug 2024, 7:07 AM
Shane Farrow
Shane Farrow - avatar
11 ответов
+ 1
if it's Angular, it should be <button (click)="add()"> Add item </button>
24th Aug 2024, 11:51 AM
Bob_Li
Bob_Li - avatar
+ 1
Hey Bob, Strangely I have just picked it up again, gone through again and it's now worked on the (click) command..... it is definitely buggy. I have experienced this previously with Sololearn. Thank you so much for the help though.
24th Aug 2024, 3:30 PM
Shane Farrow
Shane Farrow - avatar
0
Is there any function named `add` defined in the code? Was there any error message(s) on the console when you run this code? if there was, what did they (error messages) say? It would be better and bit easier to check if you can attach link to the complete code bit for analysis.
24th Aug 2024, 7:29 AM
Ipang
0
Hi, It is one of the sololearn module quizzes that I am going through. I cannot attach an image on here sadly, but one would assume the add() function is defined as the task is to insert the correct syntax where the word "onclick" is missing. The AI tells me that "onclick" is incorrect but when I ask for an explanation it says "the correct syntax should be <button onclick="add()"> So I am stuck on this one question with no way to pass it.
24th Aug 2024, 7:45 AM
Shane Farrow
Shane Farrow - avatar
0
Hi Shane, Not sure about it, but I've seen something alike before, a learner asked the AI but still couldn't get through and the quiz still assume wrong answer was given. AI is wrong if it says the correct syntax should be <button onclick="add()"> Because <button> element has a pairing ending tag </button> which it did not recommend. I suggest to just wait a bit, perhaps this is something common and someone had it figured out.
24th Aug 2024, 7:57 AM
Ipang
0
Thanks for your reply. It's very frustrating as I am very close to completing that certification but I guess waiting is the only option. Thanks again.
24th Aug 2024, 7:59 AM
Shane Farrow
Shane Farrow - avatar
0
what course and which module?
24th Aug 2024, 11:06 AM
Bob_Li
Bob_Li - avatar
0
Hi Bob_Li thanks for the reply. Its Angular basics Components module in front end developer
24th Aug 2024, 11:34 AM
Shane Farrow
Shane Farrow - avatar
0
Hi, Thanks for this Bob_Li. I will try that. It is in conflict with the AI but worth looking at. Much appreciated.
24th Aug 2024, 12:49 PM
Shane Farrow
Shane Farrow - avatar
0
Hey Bob_Li I think it must be an error with Sololearn as I've tried this too and it still says incorrect. The AI says not to include the parenthesis and explains it should simply read: <button onclick="add()"> Add item </button> I'm at a loss
24th Aug 2024, 1:07 PM
Shane Farrow
Shane Farrow - avatar
0
your course seems different from my version, but I completed mine a long time ago, so my version might be outdated. Also, Android and Apple courses seems to be a bit different. Are you on Iphone? Sololearn courses seems buggier on Apple devices. I ended my pro subscription for a while now, so I don't have access to AI generated sections. Perhaps you are referring to those? Maybe it is buggy. I don't know, but I would not be surprised. People placed too much trust in AI. If you are already learning about Angular, AI insisting on using onclick seems odd...
24th Aug 2024, 1:26 PM
Bob_Li
Bob_Li - avatar