feat: added index page and function

This commit is contained in:
Bart van der Braak 2023-07-20 01:55:59 +02:00
parent 62f2d4651d
commit d5889749c6
2 changed files with 31 additions and 2 deletions

13
src/lib/calculate-age.ts Normal file
View file

@ -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;
}

View file

@ -1,2 +1,18 @@
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
<!-- Index.svelte -->
<script>
import { calculateAge } from "$lib/calculate-age";
export let age = calculateAge('1994-10-18');
export let girlfriendDuration = calculateAge('2011-08-08');
export let location = "Zaandam, Netherlands";
export let loves = "cats and whiskey";
export let passion = "solving problems with code and automation";
</script>
<main>
<h1>Hello, I'm Bart van der Braak!</h1>
<p>I'm {age} years old and have been with my girlfriend for {girlfriendDuration} years.</p>
<p>I'm located in {location}.</p>
<p>I love {loves}.</p>
<p>I'm passionate about {passion}.</p>
</main>