import { githubDark, githubLight } from '@pierre/highlights/themes';
import { mutedLight } from '@/app/theme';
import { raw } from '@/app/raw';
import { html } from '@/app/html';
import { Client } from './client';
import Link from 'next/link';
export default function FizzBuzzPage() {
const text = raw('app/fizzbuzz/fizzbuzz.ts');
const fizzBuzzHtml = html({
file: 'app/fizzbuzz/fizzbuzz.ts',
lang: 'ts',
themes: {
light: githubLight,
dark: githubDark,
},
});
const pageHtml = html({
file: 'app/fizzbuzz/page.tsx',
themes: {
light: mutedLight,
},
});
return (
<main>
<Client />
<div className="code-block" aria-hidden="true" dangerouslySetInnerHTML={{ __html: pageHtml }} />
<br />
<pre className="divider">{Array.from({ length: 80 }, () => '/')}</pre>
<br />
<div className="code-block" aria-hidden="true" dangerouslySetInnerHTML={{ __html: fizzBuzzHtml }} />
<section className="cloaked">
<h1>FizzBuzz</h1>
<p>Open your browser console and run fizzBuzz().</p>
<nav>
<Link href="/">Home</Link>
</nav>
<pre>{text}</pre>
</section>
</main>
);
}
// Write a program that prints the numbers from 1 to 100.
// But for multiples of three print “Fizz” instead of the
// number and for the multiples of five print “Buzz”. For
// numbers which are multiples of both three and five
// print “FizzBuzz”.
export function fizzBuzz() {
for (let i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log('FizzBuzz');
} else if (i % 3 === 0) {
console.log('Fizz');
} else if (i % 5 === 0) {
console.log('Buzz');
} else {
console.log(i);
}
}
}