Skip to content

Commit

Permalink
fix value string bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ArhanChaudhary committed Aug 23, 2024
1 parent 5971cee commit a9a85a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/lib/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { GuessType } from '../routes/+page.svelte';
import { fly } from 'svelte/transition';
export let value: number;
export let value: string;
export let message: string;
export let link: string | undefined = undefined;
export let guessType: GuessType;
Expand Down
26 changes: 14 additions & 12 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export let data;
let guesses = 0;
let modals = new Array<{ value: number; message: string; link?: string; guessType: GuessType }>();
let modals = new Array<{ value: string; message: string; link?: string; guessType: GuessType }>();
let numbersEl: HTMLDivElement;
let numbersCount = Object.keys(data.numbers).length;
let startTime: number;
Expand Down Expand Up @@ -65,18 +65,20 @@
if (e.key !== 'Enter') {
return;
}
if ((e.target as HTMLInputElement).value === '') return;
let guess = (e.target as HTMLInputElement).valueAsNumber;
let guess = (e.target as HTMLInputElement).value;
if (guess === '') return;
(e.target as HTMLInputElement).value = '';
if (
data.numbers.some(({ value, guessed }) => value === guess && guessed) ||
data.technicallyIncorrectNumbers.some(({ value, guessed }) => value === guess && guessed)
data.numbers.some(({ value, guessed }) => value.toString() === guess && guessed) ||
data.technicallyIncorrectNumbers.some(
({ value, guessed }) => value.toString() === guess && guessed
)
) {
modals = [
...modals,
{
value: guess,
value: guess.toString(),
message: 'You have already guessed this number.',
guessType: GuessType.technicallyIncorrect
}
Expand All @@ -85,26 +87,26 @@
}
let technicallyIncorrectNumber = data.technicallyIncorrectNumbers.find(
({ value }) => value === guess
({ value }) => value.toString() === guess
);
if (technicallyIncorrectNumber) {
modals = [
...modals,
{
value: technicallyIncorrectNumber.value,
value: guess,
message: technicallyIncorrectNumber.message,
guessType: GuessType.technicallyIncorrect
}
];
return;
}
let number = data.numbers.find(({ value }) => value === guess);
let number = data.numbers.find(({ value }) => value.toString() === guess);
if (number) {
modals = [
...modals,
{
value: number.value,
value: guess,
message: number.message,
link: number.link,
guessType: GuessType.correct
Expand All @@ -125,7 +127,7 @@
modals = [
...modals,
{
value: NaN,
value: '',
message,
guessType: GuessType.finished
}
Expand Down Expand Up @@ -157,7 +159,7 @@
<br />
<ol class="list-decimal pl-[2ch]">
<li>
You are being timed. Despite that, <b>prioritize minimizing guesses (&lt;30 guesses)</b>.
You are being timed. Despite that, <b>prioritize minimizing guesses (&lt;30 guesses) and avoid brute force</b>.
</li>
<li>
There are {numbersCount} computing numbers hidden within this string without overlap, ignore the
Expand Down

0 comments on commit a9a85a9

Please sign in to comment.