Files
classroomio/apps/dashboard/src/lib/mocks/react/014_react_conditionals.ts
T

176 lines
4.9 KiB
TypeScript
Raw Normal View History

import { QuestionTypes } from '../utils';
import type { ExerciseTemplate } from '$lib/utils/types';
const template: ExerciseTemplate = {
title: 'React Conditional Rendering Practical Quiz',
description: 'Test your practical knowledge of conditional rendering in React.',
questionnaire: {
questions: [
{
title: 'How can you conditionally render content in React?',
name: 'conditionalRendering',
points: 1,
order: 0,
question_type: QuestionTypes[0],
options: [
{
label: 'Using conditional statements (if-else).',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: 'Always rendering all content.',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: 'Using randomization.',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
title: 'What is the purpose of the "ternary operator" in conditional rendering?',
name: 'ternaryOperatorPurpose',
points: 1,
order: 1,
question_type: QuestionTypes[2],
2023-11-25 21:56:02 +00:00
options: []
},
{
2023-11-25 21:56:02 +00:00
title:
'How would you conditionally render "ComponentA" if a condition is true and "ComponentB" if the condition is false?',
name: 'conditionalRenderingComponents',
points: 1,
order: 2,
question_type: QuestionTypes[0],
options: [
{
label: '{condition ? <ComponentA /> : <ComponentB />}',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: '<ComponentA /> || <ComponentB />',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: '<ComponentA /> && <ComponentB />',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
title: 'In React, how do you conditionally render content based on the state?',
name: 'conditionalRenderingState',
points: 1,
order: 3,
question_type: QuestionTypes[0],
options: [
{
label: 'Using the "setState" method.',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: 'By directly modifying the state object.',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: 'State cannot be used for conditional rendering.',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
2023-11-25 21:56:02 +00:00
title:
'What is the purpose of the "map" function in conditional rendering with lists in React?',
name: 'mapFunctionPurpose',
points: 1,
order: 4,
question_type: QuestionTypes[2],
2023-11-25 21:56:02 +00:00
options: []
},
{
title: 'How do you conditionally render a list of items in React using the "map" function?',
name: 'conditionalRenderingList',
points: 1,
order: 5,
question_type: QuestionTypes[0],
options: [
{
label: '{items.map(item => <ItemComponent key={item.id} />)}',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: '{items.forEach(item => <ItemComponent />)}',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: '{items.render(item => <ItemComponent />)}',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
title: 'How can you conditionally render content based on user input in a form?',
name: 'conditionalRenderingForm',
points: 1,
order: 6,
question_type: QuestionTypes[1],
options: [
{
label: 'Using event handlers and state changes.',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: 'By hardcoding the content in the form.',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: 'By using server-side logic only.',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
title: 'What is the purpose of conditional rendering in a React form?',
name: 'conditionalRenderingFormPurpose',
points: 1,
order: 7,
question_type: QuestionTypes[2],
2023-11-25 21:56:02 +00:00
options: []
},
{
2023-11-25 21:56:02 +00:00
title:
'How would you conditionally render a component "ErrorMessage" if a form input is invalid?',
name: 'conditionalRenderingInvalidInput',
points: 1,
order: 8,
question_type: QuestionTypes[0],
options: [
{
label: '{isInvalid ? <ErrorMessage /> : null}',
2023-11-25 21:56:02 +00:00
is_correct: true
},
{
label: '{!isInvalid && <ErrorMessage />}',
2023-11-25 21:56:02 +00:00
is_correct: false
},
{
label: '{isInvalid && <ErrorMessage />}',
2023-11-25 21:56:02 +00:00
is_correct: false
}
]
},
{
title: 'Explain briefly why conditional rendering is important in React applications.',
name: 'conditionalRenderingImportance',
points: 5,
order: 9,
question_type: QuestionTypes[2],
2023-11-25 21:56:02 +00:00
options: []
}
]
}
};
export default template;