Age calculator app using vanilla Javascript
Design comparison
Solution retrospective
I couldn't (or didn't try?) to animate the numbers. I still don't know how to do it, if I can do it in pure CSS or with Javascript.
Community feedback
- @ThatDevDiazPosted over 1 year ago
I'm not 100% sure what you mean by animating the numbers but,
if you're referring to the " - -" and replacing it with the results, you should create an element : <span id="yearsResult">- -</span>
then in Javascript you're going to target this ID and store it like this:
let years = document.getelementbyid(
yearsResult
);Once stored, you're going to retrieve the results from (what I assume should have been the function calculating the years) and replace the span value with the results using basic dom manipulation. Store the results in a variable so you can then use template literals to display the results. Lets say you stored years in a variable called "calculatedYears". You can then do :
years.innerHTML =
${calculatedYears}
;and your span value will now display whatever the calculatedYears value returned from the calculation function.
Hope this helped.
Marked as helpful0@henrikkudesuPosted over 1 year ago@ThatDevDiaz This part of the project is working. There is an bonus challenge on the read.me file, which is: "See the age numbers animate to their final number when the form is submitted". I imagine it's to do some animation with the numbers in the output. For example, add n by n until you reach the output number so that it is animated in some way. I didn't quite understand either, but I think that's it.
0@ThatDevDiazPosted over 1 year agoAh I see what you mean. Yeah I’m not sure I fully understand either @henrikkudesu
0 - @NatureSon22Posted over 1 year ago
Do you want to create a random generating effect, where a random number is displayed before the actual result is revealed? I've actually implemented that using the Math.random, Set Interval, and Set Timeout functions.
function randomNumber() { function genRandomNum() { const randomNumber = Math.floor(Math.random() * 100); numField.textContent = randomNumber; } const interval = setInterval(genRandomNum, someTime); // Call genRandomNum every someTime milliseconds setTimeout(() => { clearInterval(interval); // Stop calling genRandomNum after someTime milliseconds }, someTime); }
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord