Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make select the default, make people select an answer #474

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/RunCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const RunCode: React.FC<RunCodeProps> = ({
const [selections, setSelections] = useState<string[]>([]);
const [answers, setAnswers] = useState<Array<boolean | null>>([]);
const [alert, setAlert] = useState(false);
const unanswered = 'Please select an answer';

const alertFunction = () => {
setAlert(true);
Expand All @@ -40,8 +41,8 @@ const RunCode: React.FC<RunCodeProps> = ({
if (selections.length == 0) {
const tempArr: string[] = [];
const ansArr: Array<boolean | null> = [];
questions.forEach((question) => {
tempArr.push(question.options[0]);
questions.forEach(() => {
tempArr.push('');
ansArr.push(null);
});
setSelections(tempArr);
Expand Down Expand Up @@ -123,7 +124,9 @@ const RunCode: React.FC<RunCodeProps> = ({
/>
</svg>
<p style={{ color: answers[index] ? '#31A74B' : '#a80000' }}>
{question.answerText.get(selections[index])}
{selections[index] == ''
? unanswered
: question.answerText.get(selections[index])}
</p>
<div style={{ display: answers[index] ? 'flex' : 'none' }}>
<CopyToClipboard
Expand Down
7 changes: 6 additions & 1 deletion src/components/SelectCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface SelectCodeProps {
}

const SelectCode: React.FC<SelectCodeProps> = ({ choices, handleClick }) => {
const [display, setDisplay] = useState(choices[0] || '');
const [display, setDisplay] = useState('');

const handleChange = (e: SelectChangeEvent) => {
setDisplay(e.target.value);
Expand All @@ -29,6 +29,11 @@ const SelectCode: React.FC<SelectCodeProps> = ({ choices, handleClick }) => {
inputProps={{ 'aria-label': 'Without label' }}
className="select-input"
>
<MenuItem value="">
<pre>
<code>Select</code>
</pre>
</MenuItem>
{choices.map((choice, index) => (
<MenuItem
value={choice}
Expand Down
32 changes: 31 additions & 1 deletion src/pages/Exercise2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ const questions2 = [
],
]),
},
{
options: [
'char &ptr = *x;',
'string *ptr = &x;',
'string *ptr = *x;',
'char *ptr = &x;',
],
answers: ['string *ptr = &x;', 'char *ptr = &x;'],
answerText: new Map([
[
'char &ptr = *x;',
'Not quite. Remember that the & operator is used to declare a reference before the equal sign and that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!',
],
[
'string *ptr = &x;',
'Correct! You can actually declare it as either a char or string pointer.',
],
[
'string *ptr = *x;',
'Not quite. Remember that the * operator after the equal sign dereferences a variable, meaning that you would try to find the value at memory address 3!',
],
[
'char *ptr = &x;',
'Correct! You can actually declare it as either a char or string pointer.',
],
]),
},
];

const questions3 = [
Expand Down Expand Up @@ -130,7 +157,10 @@ const Exercise2: FC = () => {
<div className="exercise-2-diagram">
<img src={Exercise2Diagram2} alt="Exercise 2 Diagram" />
</div>
<h2>How do we create a pointer to the basketball string?</h2>
<h2>
How do we create a pointer to the basketball string? (Hint: there
are 2 answers here!)
</h2>
<div className="exercise2-div">
<RunCode
questions={questions2}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/SelectCode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
font-family: $niramit;
font-size: 1.6vw;
height: fit-content;
width: fit-content;
width: 70%;

@media (max-width: 600px) {
font-size: 4vw;
Expand Down
Loading