Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Age calculator app using vanilla Javascript

@henrikkudesu

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

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

Cesar D. 400

@ThatDevDiaz

Posted

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 helpful

0

@henrikkudesu

Posted

@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
Cesar D. 400

@ThatDevDiaz

Posted

Ah I see what you mean. Yeah I’m not sure I fully understand either @henrikkudesu

0
Nature Son 1,100

@NatureSon22

Posted

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 GitHub
Discord logo

Join 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