Skip to content

Commit

Permalink
new unit circle exercise and fix display (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: Sanjna <[email protected]>
  • Loading branch information
rakilkim and SanjnaT41756 authored Apr 29, 2024
1 parent e25d56d commit e02bbaf
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 49 deletions.
32 changes: 19 additions & 13 deletions src/components/shared/ExerciseSide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import AxisParent from './Exercises/AxisParent';
import GraphExercise from './Exercises/GraphExercise';
import GraphInput from './Exercises/GraphInput';
//import AxisParent from './Exercises/AxisParent';
import UnitCircleExercise from './Exercises/UnitCircleExercise';
import UnitCircleInput from './Exercises/UnitCircleInput';
import UnitCircleParent from './Exercises/UnitCircleParent';

('./Exercises/AxisExercise');

interface ExerciseSideProps {
Expand Down Expand Up @@ -216,21 +216,27 @@ ExerciseSideProps): JSX.Element {
curExercise = (
<div>
<div>
<UnitCircleExercise
turtleAngle={1}
markers={['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0']}
labels={['A', 'C', '', 'B', '']}
/>
<UnitCircleInput
nextExercise={() => {
// console.log('unit');
<UnitCircleParent
unitCircleMarkers={[
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0'],
]}
unitCircleLabels={[
['A', 'C', '', 'B', ''],
['B', 'A', '', 'C', ''],
['', '', 'C', 'A', 'B'],
]}
directions={[
['left', 'right', '', 'right', ''],
['left', 'left', '', 'left', ''],
['', '', 'right', 'right', 'left'],
]}
toNextExercise={() => {
setDisplayExercise(displayExercise + 1);
incrementExercise();
return;
}}
markers={[['-90\xB0', '-45\xB0', '0\xB0', '45\xB0', '90\xB0']]}
labels={[['A', 'C', '', 'B', '']]}
directions={[['left', 'right', '', 'right', '']]}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/Exercises/UnitCircleExercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function UnitCircleExercise({
curAngle += angleBetweenTicks;
cursorAngle += cursorTicks;
return (
<div key={element}>
<div key={idx}>
<div
className="circle-exercise"
style={{
Expand Down
41 changes: 8 additions & 33 deletions src/components/shared/Exercises/UnitCircleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import '../../../styles/Exercises/UnitCircleInput.scss';

interface UnitCircleInputProps {
nextExercise: () => void;
markers: string[][];
labels: string[][];
answers: number[][];
questionLabels: string[][];
directions: string[][];
}

interface CircleQuestion {
label: string;
answer: string; // Should change to being strings
answer: number; // Should change to being strings
direction: string;
id: number; //This sucks lol
}

function UnitCircleInput({
nextExercise,
markers,
labels,
answers,
questionLabels,
directions,
}: UnitCircleInputProps): JSX.Element {
function MakeQuestion({ label, id, direction }: CircleQuestion): JSX.Element {
Expand All @@ -27,7 +27,7 @@ function UnitCircleInput({
};
/* lines 25-35, try to get component to look like this */
return (
<div id="unitcircle-question-container">
<div id="unitcircle-question-container" key={id}>
<p id="unitcircle-check-question">
{label} = {direction}{' '}
</p>
Expand All @@ -44,7 +44,7 @@ function UnitCircleInput({
function checkAnswer() {
// Invoked to check answers and switch to the next question or set the answer wrong
for (let i = 0; i < answers[counter].length; i++) {
if (inputText[i] != answers[counter][i]) {
if (parseInt(inputText[i]) != answers[counter][i]) {
setWrong(true);
return;
}
Expand All @@ -61,30 +61,6 @@ function UnitCircleInput({
nextExercise();
}

const answers: number[][] = [];
const questionLabels: string[][] = [];
const questionDirections: string[][] = [];
for (let i = 0; i < markers.length; i++) {
const currentAnswers = [];
const currentLabels = [];
const currentDirections = [];
const length = markers[i].length;
for (let j = 0; j < length; j++) {
if (labels[i][j] !== '') {
let multiplier = 1;
if (directions[i][j] == 'left') {
multiplier = -1;
}
currentAnswers.push(parseInt(markers[i][j].slice(0, -1)) * multiplier);
currentLabels.push(labels[i][j]);
currentDirections.push(directions[i][j]);
}
}
answers.push(currentAnswers);
questionLabels.push(currentLabels);
questionDirections.push(currentDirections);
}

function wrongMessage(isWrong: boolean) {
if (isWrong) {
return "That's not quite right. Try again!";
Expand Down Expand Up @@ -112,16 +88,15 @@ function UnitCircleInput({
for (let i = 0; i < questionLabels[counter].length; i++) {
questions.push({
label: questionLabels[counter][i],
direction: questionDirections[counter][i],
answer: answers[counter][i],
direction: directions[counter][i],
id: i,
});
}
} else {
return <h2>Done!</h2>;
}

//console.log(questionLabels[counter]);
const questionOutput = questions.map(MakeQuestion);
return (
<div className="unitcircle-question-container">
Expand Down
80 changes: 80 additions & 0 deletions src/components/shared/Exercises/UnitCircleParent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useState, useEffect } from 'react';
import '../../../styles/Exercises/AxisExercise.scss';
import UnitCircleExercise from './UnitCircleExercise';
import UnitCircleInput from './UnitCircleInput';
('./Exercises/AxisExercise');

interface UnitCircleParentProps {
unitCircleMarkers: string[][]; //2-D array for different sets of problems
unitCircleLabels: string[][];
directions: string[][];
toNextExercise: () => void;
}

function UnitCircleParent({
unitCircleMarkers,
unitCircleLabels,
directions,
toNextExercise,
}: UnitCircleParentProps): JSX.Element {
//make 2d array for answers using the non-empty elements of unitCircleLabels
const answers: number[][] = [];
const questionLabels: string[][] = [];
const questionDirections: string[][] = [];
for (let i = 0; i < unitCircleMarkers.length; i++) {
const currentAnswers = [];
const currentLabels = [];
const currentDirections = [];
const length = unitCircleMarkers[i].length;
for (let j = 0; j < length; j++) {
if (unitCircleLabels[i][j] !== '') {
let multiplier = 1;
if (directions[i][j] == 'left') {
multiplier = -1;
}
currentAnswers.push(
parseInt(unitCircleMarkers[i][j].slice(0, -1)) * multiplier
);
currentLabels.push(unitCircleLabels[i][j]);
currentDirections.push(directions[i][j]);
}
}
answers.push(currentAnswers);
questionLabels.push(currentLabels);
questionDirections.push(currentDirections);
}

const [exerciseNum, setExerciseNum] = useState(0);
function nextExercise() {
setExerciseNum(exerciseNum + 1);
} // advance to next exercise within axis inputs exercise

useEffect(() => {
if (exerciseNum == unitCircleMarkers.length) {
toNextExercise(); // update parent exercise side that axis input exercise is complete
}
}, [exerciseNum]);

return (
<div>
<UnitCircleExercise
//orientation="horizontal"
turtleAngle={1}
markers={
unitCircleMarkers[Math.min(exerciseNum, unitCircleMarkers.length - 1)]
}
labels={
unitCircleLabels[Math.min(exerciseNum, unitCircleLabels.length - 1)]
}
/>
<UnitCircleInput
answers={answers}
questionLabels={questionLabels}
directions={questionDirections}
nextExercise={nextExercise}
/>
</div>
);
}

export default UnitCircleParent;
5 changes: 3 additions & 2 deletions src/styles/Exercises/UnitCircleExercise.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
justify-content: center;
//margin: 25% 10% 15%;
//width: calc(550px + 1vw);
margin-bottom: 5%;
margin-left: 30%;
margin-bottom: 2%;
margin-left: 25%;
margin-top: 5%;
position: relative;
width: 400px;
}
Expand Down
2 changes: 2 additions & 0 deletions src/styles/Exercises/UnitCircleInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
#unitcircle-check-wrong {
@include font-styles();
color: red;
margin-bottom: 3%;
margin-top: 3%;
}

.unitcircle-wrong-box {
Expand Down

0 comments on commit e02bbaf

Please sign in to comment.