Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Created April 3, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBray/3df3f37461c44380b09843f7e0b7be23 to your computer and use it in GitHub Desktop.
Save RichardBray/3df3f37461c44380b09843f7e0b7be23 to your computer and use it in GitHub Desktop.
// App.jsx
import React, { Fragment } from "react";
// - Data
import data from "./data.json";
export default function App() {
function renderQuestions() {
return data.results.map((result, index) => (
<Question key={index} {...{result, index}} />
));
}
return (
<Fragment>
<Start />
{renderQuestions()}
<Finish />
</Fragment>
);
}
function Start() {
return (
<Fragment>
<h1>Video games</h1>
<h2>How much you know about them?</h2>
<Button text="Let's go!" func={() => scrollToElem("question-0")} />
</Fragment>
);
}
function Finish() {
return (
<Fragment>
<h3>Well done!</h3>
<h4>
You scored {calculateResult(correctAnswers, chosenAnswers)} out of {totalQuestions}
</h4>
<Button text="start over" func={() => window.location.reload()} />
</Fragment>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment