diff --git a/src/lib/calculate-age.ts b/src/lib/calculate-age.ts new file mode 100644 index 0000000..0916c0d --- /dev/null +++ b/src/lib/calculate-age.ts @@ -0,0 +1,13 @@ +export function calculateAge(birthdate: string): number { + const birthDate = new Date(birthdate); + const currentDate = new Date(); + + let age = currentDate.getFullYear() - birthDate.getFullYear(); + const monthDiff = currentDate.getMonth() - birthDate.getMonth(); + + if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) { + age--; + } + + return age; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5982b0a..3589c75 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,2 +1,18 @@ -

Welcome to SvelteKit

-

Visit kit.svelte.dev to read the documentation

+ + + +
+

Hello, I'm Bart van der Braak!

+

I'm {age} years old and have been with my girlfriend for {girlfriendDuration} years.

+

I'm located in {location}.

+

I love {loves}.

+

I'm passionate about {passion}.

+
\ No newline at end of file