Skip to content

Commit 6a2fe25

Browse files
Edwin ChanEdwin Chan
authored andcommitted
added greetings
1 parent 39437e9 commit 6a2fe25

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

app/typewriter-greeting.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,35 @@ const GREETINGS = [
2121
(name: string) => `Marcoroni is typing..., ${name}.`,
2222
(name: string) => `Search Marco The Dog, ${name}.`,
2323
(name: string) => `Be more ORZ, ${name}.`,
24-
(name: string) => `Solve these problems if you're not gay, ${name}.`
25-
24+
(name: string) => `Solve these problems if you're not gay, ${name}.`,
25+
(name: string) => `${name}! Stay determined!`,
26+
() => `Nature is written in mathematical language.`,
27+
() => `In mathematics, you don’t understand things. You just get used to them.`,
28+
(name: string) => `${name}, you forgot a ± somewhere.`,
29+
(name: string) => `${name}, you look like a trapezium.`,
30+
() => `The Riemann Hypothesis has been solved!`,
31+
() => `I still remember the thrill of solving my first integral.`,
32+
() => `Numbers don't lie.`,
33+
() => `Is it always true? Sometimes true? Or never true?`,
34+
(name: string) => `${name}, WAKE UP!`,
35+
() => `lim h->0 f(x+h) - f(x) / h`,
36+
(name: string) => `${name}" or 1 = 1 --`,
37+
() => `Take pi = 3`,
38+
() => `Eat. Sleep. Math. Repeat.`,
2639
];
2740

41+
const getRandomGreetingIndex = (exclude?: number) => {
42+
if (GREETINGS.length <= 1) return 0;
43+
let next = Math.floor(Math.random() * GREETINGS.length);
44+
if (exclude === undefined) return next;
45+
while (next === exclude) {
46+
next = Math.floor(Math.random() * GREETINGS.length);
47+
}
48+
return next;
49+
};
50+
2851
function GreetingTyper({ name }: { name: string }) {
29-
const [greetingIndex, setGreetingIndex] = useState(0);
52+
const [greetingIndex, setGreetingIndex] = useState(() => getRandomGreetingIndex());
3053
const [charIndex, setCharIndex] = useState(0);
3154
const [isDeleting, setIsDeleting] = useState(false);
3255

@@ -60,7 +83,7 @@ function GreetingTyper({ name }: { name: string }) {
6083
}
6184

6285
setIsDeleting(false);
63-
setGreetingIndex((current) => (current + 1) % GREETINGS.length);
86+
setGreetingIndex((current) => getRandomGreetingIndex(current));
6487
}, delay);
6588

6689
return () => window.clearTimeout(timer);

0 commit comments

Comments
 (0)