fixed a few bugs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "binary-quiz-frontend",
|
"name": "binary-quiz-frontend",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"author": "Zev Averbach <zev@averba.ch> (https://averba.ch)",
|
"author": "Zev Averbach <zev@averba.ch> (https://averba.ch)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import Inputs from "./components/Inputs.svelte";
|
import Inputs from "./components/Inputs.svelte";
|
||||||
import Quiz from "./components/Quiz.svelte";
|
import Quiz from "./components/Quiz.svelte";
|
||||||
import Tally from "./components/Tally.svelte";
|
|
||||||
import {activeQuiz} from './stores'
|
import {activeQuiz} from './stores'
|
||||||
</script>
|
</script>
|
||||||
<main style="margin: 2em;">
|
<main style="margin: 2em;">
|
||||||
<h1>Binary Quiz!</h1>
|
<h1>Binary Quiz!</h1>
|
||||||
{#if ($activeQuiz)}
|
{#if ($activeQuiz)}
|
||||||
<Tally />
|
|
||||||
<Quiz />
|
<Quiz />
|
||||||
{:else}
|
{:else}
|
||||||
<Inputs />
|
<Inputs />
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
<script>
|
<script>
|
||||||
import {checkAnswer} from "../problems";
|
import {checkAnswer} from "../problems";
|
||||||
import { bits, activeProblemIndex, tally, num_problems, activeQuiz } from '../stores'
|
import {bits, activeProblemIndex, tally, num_problems, activeQuiz} from '../stores'
|
||||||
|
import Tally from "./Tally.svelte";
|
||||||
|
|
||||||
export let problem
|
export let problem
|
||||||
let displaySummary = false
|
let displaySummary = false
|
||||||
let solution
|
let solution
|
||||||
let submitted = false
|
|
||||||
let class_ = ""
|
let class_ = ""
|
||||||
|
|
||||||
const check = () => {
|
const check = () => {
|
||||||
if (checkAnswer(solution, problem)) {
|
if (checkAnswer(solution, problem)) {
|
||||||
submitted = true
|
tally.update(() => $tally + 1)
|
||||||
if ($num_problems === $activeProblemIndex + 1) {
|
if ($num_problems === $activeProblemIndex + 1) {
|
||||||
displaySummary = true
|
displaySummary = true
|
||||||
|
} else {
|
||||||
|
activeProblemIndex.update(() => $activeProblemIndex + 1)
|
||||||
}
|
}
|
||||||
activeProblemIndex.update(() => $activeProblemIndex + 1)
|
|
||||||
tally.update(() => $tally + 1)
|
|
||||||
} else {
|
} else {
|
||||||
class_ = "incorrect"
|
class_ = "incorrect"
|
||||||
}
|
}
|
||||||
@@ -22,17 +23,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
|
activeProblemIndex.update(() => 0)
|
||||||
|
tally.update(() => 0)
|
||||||
activeQuiz.update(() => false)
|
activeQuiz.update(() => false)
|
||||||
bits.update(() => null)
|
bits.update(() => null)
|
||||||
num_problems.update(() => null)
|
num_problems.update(() => null)
|
||||||
|
displaySummary = false
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if displaySummary}
|
{#if displaySummary}
|
||||||
<div>Congratulations, you've completed {$num_problems} {$bits}-bit problems!</div>
|
<div>Congratulations, you've completed {$num_problems} {$bits}-bit problems!</div>
|
||||||
<div><a on:click={reset}>Go back to home screen.</a></div>
|
<a href="#" on:click={reset}>Go back to home screen.</a>
|
||||||
{:else}
|
{:else}
|
||||||
|
<Tally />
|
||||||
<form on:submit|preventDefault={check} class="{class_} problem">
|
<form on:submit|preventDefault={check} class="{class_} problem">
|
||||||
<label>
|
<label>
|
||||||
{problem} =
|
{problem} =
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export const MIN_BITS = 3
|
export const MIN_BITS = 3
|
||||||
export const MAX_BITS = 16
|
export const MAX_BITS = 16
|
||||||
export const MIN_PROBLEMS = 1
|
export const MIN_PROBLEMS = 2
|
||||||
export const MAX_PROBLEMS = 99
|
export const MAX_PROBLEMS = 99
|
||||||
export const MAX_DIGITS_PROBLEMS = MAX_PROBLEMS.toString().length
|
export const MAX_DIGITS_PROBLEMS = MAX_PROBLEMS.toString().length
|
||||||
export const MAX_DIGITS_BITS = MAX_BITS.toString().length
|
export const MAX_DIGITS_BITS = MAX_BITS.toString().length
|
||||||
|
|||||||
Reference in New Issue
Block a user