fixed a few bugs

This commit is contained in:
2020-06-15 01:11:24 +02:00
parent 59c0b50a4e
commit 58da4c08a0
4 changed files with 13 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "binary-quiz-frontend",
"version": "0.0.3",
"version": "0.0.4",
"author": "Zev Averbach <zev@averba.ch> (https://averba.ch)",
"license": "MIT",
"scripts": {

View File

@@ -1,13 +1,11 @@
<script>
import Inputs from "./components/Inputs.svelte";
import Quiz from "./components/Quiz.svelte";
import Tally from "./components/Tally.svelte";
import {activeQuiz} from './stores'
</script>
<main style="margin: 2em;">
<h1>Binary Quiz!</h1>
{#if ($activeQuiz)}
<Tally />
<Quiz />
{:else}
<Inputs />

View File

@@ -1,20 +1,21 @@
<script>
import {checkAnswer} from "../problems";
import {bits, activeProblemIndex, tally, num_problems, activeQuiz} from '../stores'
import Tally from "./Tally.svelte";
export let problem
let displaySummary = false
let solution
let submitted = false
let class_ = ""
const check = () => {
if (checkAnswer(solution, problem)) {
submitted = true
tally.update(() => $tally + 1)
if ($num_problems === $activeProblemIndex + 1) {
displaySummary = true
}
} else {
activeProblemIndex.update(() => $activeProblemIndex + 1)
tally.update(() => $tally + 1)
}
} else {
class_ = "incorrect"
}
@@ -22,17 +23,21 @@
}
const reset = () => {
activeProblemIndex.update(() => 0)
tally.update(() => 0)
activeQuiz.update(() => false)
bits.update(() => null)
num_problems.update(() => null)
displaySummary = false
}
</script>
{#if displaySummary}
<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}
<Tally />
<form on:submit|preventDefault={check} class="{class_} problem">
<label>
{problem} =

View File

@@ -1,6 +1,6 @@
export const MIN_BITS = 3
export const MAX_BITS = 16
export const MIN_PROBLEMS = 1
export const MIN_PROBLEMS = 2
export const MAX_PROBLEMS = 99
export const MAX_DIGITS_PROBLEMS = MAX_PROBLEMS.toString().length
export const MAX_DIGITS_BITS = MAX_BITS.toString().length