Skip to content

Commit 1f111e9

Browse files
committed
0.0.5 update
1 parent 1718376 commit 1f111e9

11 files changed

+273
-77
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.0.5
2+
- Now titles are used for comparisons rather than ids since ids are hard to make unique and are tied to section-ids(maybe crc32 the titles for uids)
3+
- Prevent re-doing of problems that are already marked correct when the user did not click "Next" to proceed.
4+
- Added clear cache button
5+
- Added show answer button
6+
- Added cloudflare analytics
7+
- Input answers are now space insensitive
8+
- Input answer hints now can take html
9+
- Breaking ProblemSet constructor because search tags are kinda optional and should be last
110
# 0.0.4
211
- Fixed TOC not updating
312
- Merged back other deleted props rather than just .gen()

public/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset='utf-8'>
56
<meta name='viewport' content='width=device-width,initial-scale=1'>
67

8+
<!-- Cloudflare Web Analytics -->
9+
<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
10+
data-cf-beacon='{"token": "94ff6f49ae794e9fb35547e18ce0d8de"}'></script><!-- End Cloudflare Web Analytics -->
11+
712
<title>jestlearn</title>
813

914
<link rel='icon' type='image/png' href='./favicon.png'>
@@ -16,4 +21,5 @@
1621

1722
<body>
1823
</body>
19-
</html>
24+
25+
</html>

src/InputProblem.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
// using coersion here. might have to handle cases where evaluation of the expression needs to be done before checking answer
1313
// or force everyone to genereate the json evaluted??
1414
//console.log(data.answer);
15+
//answer can optionally be space insensitive
16+
1517
let is_correct =
1618
data.answer == input_answer ||
17-
data.answer.toString().toLowerCase() == input_answer.toLowerCase();
19+
data.answer.toString().toLowerCase() == input_answer.toLowerCase() ||
20+
data.answer.toString().replace(/\s/g, "") ===
21+
input_answer.replace(/\s/g, "");
1822
return is_correct;
1923
});
2024
$: dispatch("valid-input", input_answer.length > 0);
@@ -28,7 +32,9 @@
2832
<div>
2933
{@html data.question}
3034
</div>
31-
<p>{data.input_answer_hint}</p>
35+
<p>
36+
{@html data.input_answer_hint}
37+
</p>
3238
<input
3339
type="text"
3440
bind:value={input_answer}
@@ -40,8 +46,14 @@
4046
/>
4147
{#if show_answer_option}
4248
<details>
43-
<summary>show answer</summary>
49+
<summary><span class="red">show answer</span></summary>
4450
{data.answer}
4551
</details>
4652
{/if}
4753
</div>
54+
55+
<style>
56+
.red {
57+
color: red;
58+
}
59+
</style>

src/ProblemSet.svelte

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010
1111
export let data: ProblemSet;
1212
const dispatch = createEventDispatcher();
13-
13+
function check_already_answered_beforehand() {
14+
if (data.problems.length > 0) {
15+
return (
16+
data.problems[data.problem_index].result === "" ||
17+
data.problems[data.problem_index].result === "⚠️"
18+
);
19+
} else {
20+
return false;
21+
}
22+
}
1423
let check_answer;
15-
let is_valid = false;
16-
let enable_next_button = false;
24+
let is_valid = false || check_already_answered_beforehand();
25+
let enable_next_button = false || check_already_answered_beforehand();
1726
/* let problem_index =
1827
progress.indexOf(Result.UNANSWERED) !== -1
1928
? progress.indexOf(Result.UNANSWERED)
@@ -28,6 +37,12 @@
2837
reset_input_answer = false;
2938
data.problems[data.problem_index].tries += 1;
3039
if (check_answer && check_answer()) {
40+
if (check_already_answered_beforehand()) {
41+
//we already did this problem so just enable the next button and return early
42+
43+
enable_next_button = true;
44+
return;
45+
}
3146
if (data.problems[data.problem_index].tries == 1) {
3247
//got it right on the first try
3348
data.problems[data.problem_index].result = "";
@@ -94,6 +109,9 @@
94109
dispatch("save", { code: code });
95110
reset_input_answer = true;
96111
}
112+
/* TODO:
113+
CONSIDER REMOVING INPUTPROBLEM AND SELECT PROBLEM NEEDING TO COMMUNICATE BACK UP HERE!
114+
UPDATE-CHECK EVENTS SHOULD BE CONTAINED IN THOSE FILES INSTEAD? Would need to refactor them so they can take an entire array of problems rather than being passed down 1 and having this file control everything*/
97115
</script>
98116

99117
<title>{data.title}</title>

src/ProblemSet.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Problem {
2929

3030
export class ProblemSet {
3131
title: string;
32-
///ids must be unique!
32+
///id is for section identification
3333
id: number;
3434
problem_index: number;
3535
tags: string[];
@@ -43,11 +43,11 @@ export class ProblemSet {
4343
constructor(
4444
title: string,
4545
id: number,
46-
tags: string[],
4746
gen: Function | undefined,
4847
problems: Problem[] = [],
4948
resources: { url_title: string; url: string; additional: string }[] = [],
50-
emoji_mark: string = "❓"
49+
tags: string[] = [],
50+
emoji_mark: string = "❓",
5151
) {
5252
this.title = title;
5353
this.id = id;
@@ -72,7 +72,7 @@ export function has_started(problems: Problem[]): boolean {
7272
//adds back the gen() functions that were not seralized
7373
export function merge_back_deleted_props(without: ProblemSet[], original: ProblemSet[]): ProblemSet[] {
7474
return without.map((val) => {
75-
let found = original.find((hay) => val.id === hay.id);
75+
let found = original.find((hay) => val.title === hay.title);
7676
if(found) {
7777
val.gen = found.gen;
7878
val.resources = found.resources;

src/data.ts

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import { object_without_properties } from "svelte/internal";
22
import { ProblemSet, Problem, gen_amount } from "./ProblemSet";
3+
4+
function fetch_problems(id: number = 0, amount = 5) {
5+
return async function get_it() {
6+
//const fetch_url = "http://localhost:3000/exercise";
7+
const fetch_url = "https://jestlearn.com/exercise";
8+
let response = await fetch(fetch_url, {
9+
method: "POST",
10+
headers: {
11+
"Content-Type": "application/json",
12+
},
13+
body: JSON.stringify({ id: id, amount: amount }),
14+
});
15+
let result = await response.json();
16+
return result;
17+
}
18+
}
19+
320
/// min and max are inclusive
421
function ran_int(min = 0, max = 1) {
522
min = Math.ceil(min);
@@ -12,22 +29,24 @@ function ran_bool() {
1229
}
1330

1431
let racket_math_expressions = new ProblemSet(
15-
"Expressions, Numbers, and Evaluation",
32+
"Expressions and Evaluation with numbers",
1633
2.0,
34+
fetch_problems(0, 10),
1735
[],
18-
async function get_it() {
19-
let id = 0;
20-
let amount = 10;
21-
let response = await fetch("https://jestlearn.com/exercise", {
22-
method: "POST",
23-
headers: {
24-
"Content-Type": "application/json",
25-
},
26-
body: JSON.stringify({ id: id, amount: amount }),
27-
});
28-
let result = await response.json();
29-
return result;
30-
},
36+
[
37+
{
38+
url_title: "article",
39+
url: "https://jesthowtocode.netlify.app/expressions.html",
40+
additional: "",
41+
},
42+
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
43+
]
44+
);
45+
46+
let infix_to_prefix = new ProblemSet(
47+
"Translate infix to prefix math",
48+
2.1,
49+
fetch_problems(2.1, 10),
3150
[],
3251
[
3352
{
@@ -42,8 +61,7 @@ let racket_math_expressions = new ProblemSet(
4261
let racket_string_practice = new ProblemSet(
4362
"Zero based indexing string practice",
4463
2.2,
45-
[],
46-
gen_amount(10, function get_it() {
64+
gen_amount(10, function gen_problem() {
4765
let ran_words = [
4866
"StRiKeBrEaKeR",
4967
"InVeStIgAtIoN",
@@ -105,11 +123,70 @@ let racket_string_practice = new ProblemSet(
105123
]
106124
);
107125

126+
let ran_var_arith = new ProblemSet(
127+
"Variable arith evaluation",
128+
2.3,
129+
fetch_problems(2.3, 10),
130+
[],
131+
[
132+
{
133+
url_title: "article",
134+
url: "https://jesthowtocode.netlify.app/expressions.html",
135+
additional: "",
136+
},
137+
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
138+
]
139+
);
140+
141+
let build_a_string = new ProblemSet(
142+
"Build a string",
143+
2.4,
144+
fetch_problems(2.4, 10),
145+
[],
146+
[
147+
{
148+
url_title: "article",
149+
url: "https://jesthowtocode.netlify.app/expressions.html",
150+
additional: "",
151+
},
152+
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
153+
]
154+
);
155+
156+
let comparisons = new ProblemSet(
157+
"If bool comparisons",
158+
2.5,
159+
fetch_problems(2.5, 10),
160+
[],
161+
[
162+
{
163+
url_title: "article",
164+
url: "https://jesthowtocode.netlify.app/expressions.html",
165+
additional: "",
166+
},
167+
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
168+
]
169+
);
170+
171+
let logical = new ProblemSet(
172+
"If logical",
173+
2.6,
174+
fetch_problems(2.6, 10),
175+
[],
176+
[
177+
{
178+
url_title: "article",
179+
url: "https://jesthowtocode.netlify.app/expressions.html",
180+
additional: "",
181+
},
182+
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
183+
]
184+
);
108185

109186
function pick_random_el(arr: any[]) {
110187
return arr[Math.floor(Math.random() * arr.length)];
111188
}
112-
let all: ProblemSet[] = [racket_math_expressions, racket_string_practice];
189+
let all: ProblemSet[] = [racket_math_expressions, infix_to_prefix, racket_string_practice, ran_var_arith, build_a_string, comparisons, logical];
113190
//WARNING: do not stringify this! we need the gen function and a copy of the original questions for resetting and other things
114191
export const TOC_original: ProblemSet[] = all.map((val) => Object.freeze(val));
115192

src/data_computer_systems.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,50 +253,38 @@ let binary_num_resources = [
253253
{ url_title: "video", url: "https://youtu.be/bFLB4dyNKUk", additional: "" },
254254
];
255255

256-
257-
258256
export let all = [
259257
new ProblemSet(
260258
"Binary To Decimal",
261259
0.0,
262-
[],
263260
gen_amount(5, generate_binary_to_decimal),
264261
[],
265262
binary_num_resources
266263
),
267264
new ProblemSet(
268265
"Decimal To Binary",
269266
0.1,
270-
[],
271267
gen_amount(5, generate_decimal_to_binary),
272268
[],
273269
binary_num_resources
274270
),
275-
new ProblemSet("Binary to Hex", 2.1, [], gen_amount( 5, generate_binary_to_hex)),
276-
new ProblemSet("Hex to Binary", 2.1, [], gen_amount(5,generate_hex_to_binary)),
277-
new ProblemSet(
278-
"Decimal to Hex",
279-
2.3,
280-
[],
281-
gen_amount(5, generate_decimal_to_hex)
282-
),
283-
new ProblemSet("Hex to Decimal", 2.3, [], gen_amount(5, generate_hex_to_decimal)),
271+
new ProblemSet("Binary to Hex", 2.1, gen_amount(5, generate_binary_to_hex)),
272+
new ProblemSet("Hex to Binary", 2.1, gen_amount(5, generate_hex_to_binary)),
273+
new ProblemSet("Decimal to Hex", 2.3, gen_amount(5, generate_decimal_to_hex)),
274+
new ProblemSet("Hex to Decimal", 2.3, gen_amount(5, generate_hex_to_decimal)),
284275
new ProblemSet(
285276
"Bitwise Operations",
286277
2.8,
287-
[],
288278
gen_amount(5, generate_bitwise_vec_operations)
289279
),
290280
new ProblemSet(
291281
"Bitshifting (arithmetic and logical)",
292282
2.16,
293-
[],
294283
gen_amount(20, generate_bitwise_shift)
295284
),
296285
new ProblemSet(
297286
"Binary Addition(unsigned)",
298287
2.17,
299-
[],
300288
gen_amount(10, function gen_binary_addtion_unsigned() {
301289
let bit_width = ran_int(4, 8);
302290
let UMAX = Math.pow(2, bit_width) - 1;
@@ -348,7 +336,6 @@ export let all = [
348336
new ProblemSet(
349337
"Decimal to Binary(two's complement)",
350338
2.17,
351-
[],
352339
gen_amount(10, generate_decimal_to_twoscomp),
353340
[],
354341
[
@@ -367,7 +354,6 @@ export let all = [
367354
new ProblemSet(
368355
"Binary to Decimal(unsigned and signed twos compl)",
369356
2.19,
370-
[],
371357
gen_amount(10, generate_twoscomp_to_deci),
372358
[],
373359
[
@@ -386,7 +372,6 @@ export let all = [
386372
new ProblemSet(
387373
"Binary Subtraction(two's complement)",
388374
2.19,
389-
[],
390375
gen_amount(10, function gen_sub_problem() {
391376
//twos complement only! no need to do unsigned + signed
392377
let bit_width = ran_int(4, 8);
@@ -420,7 +405,6 @@ export let all = [
420405
new ProblemSet(
421406
"Signed Overflow",
422407
2.29,
423-
[],
424408
gen_amount(10, function gen_signed_overflow_prob() {
425409
//twos complement only! no need to do unsigned + signed
426410
let bit_width = ran_int(4, 8);

0 commit comments

Comments
 (0)