Skip to content

Commit

Permalink
101 error message graph (#108)
Browse files Browse the repository at this point in the history
* added wrong message to graphs

* added error message to graph + fixed graph styling

* shifted graph

---------

Co-authored-by: Sanjna <[email protected]>
  • Loading branch information
NotAmaia and SanjnaT41756 authored May 29, 2024
1 parent 667dd0b commit 5283384
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/shared/Exercises/GraphExercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ GraphProps): JSX.Element {
const dyPercent = yPos(endY) - yPos(startY);
// use this factor because dyPercent is relative to height,
// but we express a line's length as a percentage of width.
const yxRatio = 22.5 / 50;
const yxRatio = 14.5 / 31;
const lineLengthPercent =
Math.sqrt(
(dxPercent / 100) ** 2 + ((dyPercent * yxRatio) / 100) ** 2
Expand Down
17 changes: 15 additions & 2 deletions src/components/shared/Exercises/GraphInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//import { useState } from 'react';
//import { useState } from 'react';
import { useState } from 'react';
import '../../../styles/Exercises/GraphInput.scss';

interface GraphQuestionData {
Expand Down Expand Up @@ -105,14 +105,24 @@ function GraphInput({
//console.log(i);
if (!i) {
//console.log(`${i} is incorrect`);
//setWrong(true);
setWrong(true);
return;
}
}
//console.log('all right!');
nextExercise();
};

function wrongMessage(isWrong: boolean) {
if (isWrong) {
return "That's not quite right. Try again!";
} else {
return;
}
}

const [wrong, setWrong] = useState(false);

const makeLine = (
data: GraphLineData,
setCorrect: (id: number, value: boolean) => void
Expand All @@ -128,6 +138,9 @@ function GraphInput({
<div id="graphinput-question-box">
{questionArray.map((x) => makeLine(x, setValueCorrect))}
</div>
<div className="axinput-wrong-box">
<h3 id="axinput-check-wrong">&nbsp;{wrongMessage(wrong)}&nbsp;</h3>
</div>
<div id="graphinput-check-button-container">
<button id="graphinput-check-button" onClick={checkCorrect}>
Check
Expand Down
15 changes: 13 additions & 2 deletions src/styles/Exercises/GraphInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
margin-bottom: 2vh;
margin-left: 0;
margin-right: auto;
margin-top: 150px;
margin-top: 50px;
padding-left: 8%;
}

Expand Down Expand Up @@ -78,7 +78,9 @@

#graphinput-check-button-container {
align-self: center;
padding-top: 4vh;
padding-bottom: 10vh;
//padding-top: 4vh;
position: relative;
}

#graphinput-check-button {
Expand All @@ -89,3 +91,12 @@
color: colors.$text-white;
padding: 1.25vw 2.5vw;
}

#graphinput-check-wrong {
@include font-styles();
color: red;
}

.graphinput-wrong-box {
align-self: center;
}
6 changes: 3 additions & 3 deletions src/styles/Graph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
border: solid 1px rgb(209, 209, 209);
border-radius: 12px;
height: 0;
margin-left: 5%;
margin-left: 15%;
// If editing the sizing of graph-container (padding-bottom or width),
// modify the value of `yxRatio` in Graph.tsx
padding-bottom: 22.5%;
padding-bottom: 14.5%;
position: absolute;
top: 5%;
width: 50%; // see above warning
width: 31%; // see above warning
}

.grid-line {
Expand Down

0 comments on commit 5283384

Please sign in to comment.