Skip to content

Commit

Permalink
Fixed map initialization and added more answers #53
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Oct 17, 2023
1 parent e0f1a24 commit f88a969
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/components/shared/ExerciseSide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function ExerciseSide({ incrementExercise }: ExerciseSideProps): JSX.Element {
const [completeExercises, setCompleteExercises] = useState(0);
type availableExercises = 'axis' | 'congrats' | 'circle' | 'graph';

const exercises: availableExercises[] = ['axis', 'graph', 'congrats'];
const exercises: availableExercises[] = ['graph', 'congrats'];
let curExercise;

if (exercises[completeExercises] == 'graph') {
Expand Down Expand Up @@ -50,35 +50,39 @@ function ExerciseSide({ incrementExercise }: ExerciseSideProps): JSX.Element {
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2, id: 0, answer: '1' },
{ type: 'input', width: 2, id: 0, answer: '0' },
{ type: 'text', text: ', -1)' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.setheading(' },
{ type: 'input', width: 4, id: 1 },
{ type: 'input', width: 4, id: 1, answer: '2' },
{ type: 'text', text: ')' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.' },
{ type: 'input', width: 8, id: 2 },
{ type: 'input', width: 8, id: 2, answer: '4' },
{ type: 'text', text: '()' },
],
},
{
textArray: [
{ type: 'text', text: 'turtle.goto(' },
{ type: 'input', width: 2, id: 3 },
{ type: 'input', width: 2, id: 3, answer: '6' },
{ type: 'text', text: ', ' },
{ type: 'input', width: 2, id: 4 },
{ type: 'input', width: 2, id: 4, answer: '8' },
{ type: 'text', text: ')' },
],
},
]}
nextExercise={() => incrementExercise()}
nextExercise={() => {
setCompleteExercises(completeExercises + 1);
incrementExercise();
return;
}}
/>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions src/components/shared/Exercises/GraphInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//import { useState } from 'react';
//import { useState } from 'react';
import '../../../styles/Exercises/GraphInput.scss';

interface GraphQuestionData {
Expand Down Expand Up @@ -86,7 +87,13 @@ function GraphInput({
nextExercise,
}: GraphInputProps): JSX.Element {
const valueMap = new Map<number, boolean>();
//const [wrong, setWrong] = useState(false);
for (const question of questionArray) {
for (const item of question.textArray) {
if (item.type == 'input') {
valueMap.set(item.id ?? -1, false);
}
}
}
const setValueCorrect = (id: number, value: boolean): void => {
console.log(`Setting ${id} to ${value}`);
valueMap.set(id, value);
Expand All @@ -102,8 +109,9 @@ function GraphInput({
//setWrong(true);
return;
}
nextExercise();
}
console.log('all right!');
nextExercise();
};

const makeLine = (
Expand Down

0 comments on commit f88a969

Please sign in to comment.