+ 1

Click function

https://code.sololearn.com/W8fgZaSBq1fM/?ref=app Why does it say that it can’t find variable donut?

6th Jun 2020, 5:25 PM
Sali65
Sali65 - avatar
6 Réponses
+ 2
First of all -step by step- I recommend to test the code‘s functions without using of images, e.g. with a div. Then you can see where are the realy problems.
6th Jun 2020, 7:49 PM
JaScript
JaScript - avatar
8th Jun 2020, 10:38 PM
Sali65
Sali65 - avatar
0
Didn't you write it wrong?
6th Jun 2020, 5:26 PM
Alexandre
Alexandre - avatar
0
No,
6th Jun 2020, 5:27 PM
Sali65
Sali65 - avatar
0
The error says that you have an extra" )". I took it and then you had an extra" }". Then, it started to work <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!--This is simular to my character gender--> </head> <body> <img onclick="donut()"src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/delish-190829-baked-donuts-0027-landscape-pf-1569986899.jpg?crop=0.668xw:1.00xh;0.167xw,0&resize=640:*"/> <script> alert("Tap the img to change the donut!") function donut() { var donuts = "many" $("img").attr("src","https://myfox8.com/wp-content/uploads/sites/17/2020/06/banner.jpg?w=1180&h=700&crop=1") if (donuts == "many") { $("img").on("click",function() { $("img").attr("src","https://bakingamoment.com/wp-content/uploads/2017/04/2803-strawberry-donuts-square.jpg") donuts ="pink" }) } else if(donuts == "pink") { $("img").attr("src","https://hips.hearstapps.com/hmg-p
6th Jun 2020, 5:33 PM
Alexandre
Alexandre - avatar
0
There is one more that says they cant find the variable donut at line 9. But thats where i put a comment
6th Jun 2020, 7:34 PM
Sali65
Sali65 - avatar