Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- </head>
- <title>
- </title>
- <script>
- var image;
- var imageSchedule;
- var score = 0 ;
- function startAnimation(){
- var displayimage = document.getElementById("image");
- displayimage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- imageSchedule = setInterval(showimage, 1000);
- }
- function showimage(){
- var displayimage = document.getElementById("image");
- if (displayimage.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png" {
- displayimage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png";
- }
- else if (displayimage.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png" {
- displayimage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- }
- }
- function stopimage(){
- clearInterval(imageSchedule);
- }
- function score(){
- var image = document.getElementById("image");
- if image.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png" {
- score += 1;
- }else if image.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png"{
- score -= 1;
- var span = document.getElementById("image123");
- span.innerHTML = score;
- }
- }
- </script>
- <body>
- <button onClick="startAnimation()" >
- Start Animation
- </button>
- <button onClick="stopimage()" >
- Stop Animation
- </button>
- <br>
- <br>
- <br>
- <img id="image" onclick="score()">
- <br>
- Your score: <span id="image123" ></span>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement