Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- question 4 -->
- var fish;
- var imageSchedule;
- function startAnimation(){
- var fishImage = document.getElementById("fish");
- fishImage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- imageSchedule = setInterval(showimage, 1000);
- }
- function showimage(){
- var fishImage = document.getElementById("fish");
- if (fishImage.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png") {
- fishImage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png";
- }
- else if (fishImage.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png") {
- fishImage.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- }
- }
- function stopAnimation(){
- clearInterval(imageSchedule);
- }
- <!-- question 5 -->
- var image;
- var imageSchedule;
- var image2 = 0;
- var userScore = 0 ;
- function startGame(){
- var image2 = document.getElementById("image1");
- image2.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- imageSchedule = setInterval(showFish, 1000);
- }
- function showFish(){
- var image2 = document.getElementById("image1");
- if (image2.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png") {
- image2.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png";
- }
- else if (image2.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png") {
- image2.src = "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png";
- }
- }
- function stopGame(){
- clearInterval(imageSchedule);
- }
- function score(){
- var image = document.getElementById("image1");
- if (image.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/happy_fish.png") {
- userScore += 5;
- }
- else if (image.src == "https://www.uow.edu.au/~dong/w3/assignment/a5/sad_fish.png"){
- userScore -= 5;
- }
- var span = document.getElementById("image_1");
- span.innerHTML = userScore;
- if (userScore == 10){
- span.innerHTML = userScore + " you win" ;
- }
- else if (userScore == - 10){
- span.innerHTML = userScore + " you lose" ;
- }
- }
- <button onclick="startAnimation()" > Start Animation </button>
- <button onclick="stopAnimation()" > Stop Animation </button>
- <br>
- <br>
- <img id="fish">
- <hr>
- <button onClick="startGame()"> Start Animation </button>
- <button onClick="stopGame()"> Stop Animation </button>
- <br>
- <br>
- <br>
- <img id="image1" onclick="score()">
- <br>
- Your score: <span id="image_1" ></span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement