28
loading...
This website collects cookies to deliver better user experience
Trained on billions of lines of public code, GitHub Copilot puts the knowledge you need at your fingertips, saving you time and helping you stay focused.
— GitHub
index.tsx
or the home page./*
render a Center with h="100vh" and a VStack with no props.
The VStack is a stack of three elements:
- a Heading with as="h1" and size="3xl" with Text "Bamboozled"
- a Text with fontSize="xl" and pb={10} with Text "made by winnekes and Github Copilot"
- if !isQuizRunning render a Button component with the text "Start the quiz now",
size="lg" and onClick={() => setIsQuizRunning(true)}
- if IsQuizRunning render the Quiz component
*/
return (
<div>
<div style={{ height: "100vh" }}>
<div style={{ display: "flex", flexDirection: "column" }}>
<h1 as="h1" style={{ fontSize: "3xl" }}>Bamboozled</h1>
<p style={{ fontSize: "xl", paddingBottom: "10px" }}>
made by winnekes and Github Copilot
</p>
{!isQuizRunning && (
<button
style={{
fontSize: "lg",
border: "none",
background: "none",
color: "white",
padding: "10px",
borderRadius: "3px"
}}
onClick={() => setIsQuizRunning(true)}
>
Start the quiz now
</button>
)}
{isQuizRunning && <Quiz />}
</div>
</div>
</div>
);
}
...
import { Quiz } from "./quiz";
import { Center, VStack, Heading, Text, Button } from "@chakra-ui/react";
...
/*
render a Center with h="100vh" and a VStack with no props.
The VStack is a stack of three elements:
- a Heading with as="h1" and size="3xl" with Text "Bamboozled"
- a Text with fontSize="xl" and pb={10} with Text "made by winnekes and Github Copilot"
- if !isQuizRunning render a Button component with the text "Start the quiz now",
size="lg" and onClick={() => setIsQuizRunning(true)}
- if IsQuizRunning render the Quiz component
*/
return (
<Center h="100vh">
<VStack>
<Heading as="h1" size="3xl">
Bamboozled
</Heading>
<Text fontSize="xl" pb={10}>
made by winnekes and Github Copilot
</Text>
{isQuizRunning ? (
<Quiz />
) : (
<Button size="lg" onClick={() => setIsQuizRunning(true)}>
Start the quiz now
</Button>
)}
</VStack>
</Center>
);
true
or false
as the answer but rather the string equivalents, "True"
and "False"
, so I asked the Copilot to create a method that converts string to boolean.// create a function called getBooleanFromString that returns true if the string is "True"
const getBooleanFromString = (value: string): boolean => {
return value === "True";
};
const validateAnswer = (answer: boolean): void => {
if (answer === questions[currentQuestion].correctAnswer) {
setQuestionsCorrectlyAnsweredCount(questionsCorrectlyAnsweredCount + 1);
}
setCurrentQuestion(currentQuestion + 1);
};
// compare the answer of the user with questions[currentQuestion].correctAnswer
// in a function called validateAnswer
// and increment questionsCorrectlyAnsweredCount by one if the answer is correct.
// Then increment currentQuestion by one.
const validateAnswer = (answer: string): boolean => {
const correctAnswer = questions[currentQuestion].correctAnswer;
return correctAnswer === answer;
};
answer
is not boolean, and the function isn't updating the state as instructed. Let's improve the comment a bit:// Copilot, compare the answer(boolean) of the user with questions[currentQuestion].correctAnswer
// in a function called validateAnswer
// and increment questionsCorrectlyAnsweredCount by one if the answer is correct.
// Then increment currentQuestion by one.
const validateAnswer = (answer: boolean): boolean => {
const correctAnswer = getBooleanFromString(questions[currentQuestion].correctAnswer);
if (correctAnswer === answer) {
setQuestionsCorrectlyAnsweredCount(
setQuestionsCorrectlyAnsweredCount(questionsCorrectlyAnsweredCount + 1)
);
}
setCurrentQuestion(setCurrentQuestion(currentQuestion + 1));
return true;
};
answer
is a boolean now. But the Copilot is for some reason using the method getBooleanFromString
that it created just before — maybe it is just very proud of the code it generated and wanted to use it. I don't know what spaghetti mess is happening with the state methods, and for some reason we are returning true
.// Copilot, in a function called validateAnswer compare the answer, a boolean value, with questions[currentQuestion].correctAnswer
// and increment questionsCorrectlyAnsweredCount by one using setQuestionsCorrectlyAnsweredCount if the answer is correct.
// Then always increment currentQuestion using setCurrentQuestion by one.
// Don't use the function getBooleanFromString!
// The function does not return anything.
const validateAnswer = (answer: boolean): void => {
if (answer === questions[currentQuestion].correctAnswer) {
setQuestionsCorrectlyAnsweredCount(questionsCorrectlyAnsweredCount + 1);
}
setCurrentQuestion(currentQuestion + 1);
};
Question
type with little modification.Question
objects (keys being question
and answer
, provide a couple of questions and Copilot will add more! This is great for generating mock-dataDevelopers should be as afraid of GitHub Copilot as mathematicians are of calculators.
— Kelsey Hightower (@kelseyhightower) July 7, 2021