subject

In this lab, you will use a timer to animate the movement of a heart image to the location where the mouse clicks, as shown below. The given web page shows a heart image. When the user clicks anywhere in the page, the startAnimation() function is called. startAnimation() determines where the user clicked and calls moveImage() with the clicked (x, y) coordinate. moveImage() moves the heart 1 pixel in the direction of the given (x, y) coordinates.
Make the following JavaScript modifications using clearInterval() and setInterval() where appropriate:
In startAnimation(), add an if statement that stops the timer with the ID timerId if timerId is not null.
In startAnimation(), start a timer that calls moveImage(clickX, clickY) every 10 milliseconds. Save the timer ID in the timerId variable.
Add an if statement in moveImage() that stops the timer with the ID timerId if (imgX, imgY) is equal to (centerX, centerY). Also set timerId to null.
After the modifications are complete, the user should be able to click anywhere in the browser, and the heart will move to the clicked location.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Alex’s family members live in different parts of the world. they would like to discuss the wedding plans of one of their distant relatives. however, alex wants all the family members to talk to each other simultaneously so that they can make decisions quickly. which mode of internet communication should they use? a. blog b. email c. wiki d. message board e. instant messaging
Answers: 2
question
Computers and Technology, 23.06.2019 15:30
The processing of data in a computer involves the interplay between its various hardware components.
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
The keyboard usually has six rows of keys. which of the following is not one of the key group categories? letter keys number keys control keys graphic keys
Answers: 1
You know the right answer?
In this lab, you will use a timer to animate the movement of a heart image to the location where the...
Questions
question
Biology, 07.01.2021 20:20
question
Social Studies, 07.01.2021 20:20
question
Arts, 07.01.2021 20:20
question
Mathematics, 07.01.2021 20:20
Questions on the website: 13722363