+ 1
Click function
https://code.sololearn.com/W8fgZaSBq1fM/?ref=app Why does it say that it can’t find variable donut?
6 odpowiedzi
+ 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.
+ 1
Nevermind, i made a remake
https://code.sololearn.com/Wr65FB7IK6NU/?ref=app
0
Didn't you write it wrong?
0
No,
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
0
There is one more that says they cant find the variable donut at line 9. But thats where i put a comment