Skip to content

Commit

Permalink
Add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielx committed Aug 8, 2021
1 parent f2ac9b9 commit 154e235
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function App() {
//Generate options array of 3 random countries + one correct
while (countries.length > 0 && opt.length < 4) {
let newCountry = pickRandomCountry();
//Check if country already exists in options array
if (!opt.some((option) => option.name === newCountry.name)) {
opt.push(newCountry);
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const Main = ({
const [clicked, setClicked] = useState(false);

const checkAnswer = (event) => {
//Function checks if the answer is correct
//If it is, it adds the points to the score
//If it is not, it adds wrong classname, and sets the incorrect variable to true
if (!answered) {
if (event.target.children[1].innerHTML === country.name) {
event.target.className += "correct";
Expand All @@ -31,6 +34,7 @@ const Main = ({
useEffect(() => {
function generateRandomNumberArr() {
//Generate random number from 0 to 4 and push it to array if it does not contain it
//Function is used to generate answer order
const arr = [];

while (arr.length < 4) {
Expand Down Expand Up @@ -69,12 +73,16 @@ const Main = ({
));

return (
/****** Main card element ******/

<main className="Main py-20 w-full h-full flex">
<div className="Card m-auto w-full sm:w-5/6 lg:w-3/6 max-w-md min-h-2/3 bg-white rounded-xl relative">
<h1 className="CardText max-w-1/2 -top-8 md:-top-12 text-lg sm:text-3xl text-white font-bold uppercase absolute ">
Country Quiz
</h1>

{/* If incorrect answer is provided and results button is clicked
* display results page
* */}
{incorrect && clicked ? (
<div className="flex flex-col items-center p-10 gap-3">
<img
Expand All @@ -93,6 +101,7 @@ const Main = ({
</span>{" "}
correct answers!
</p>
{/* Button resets stats and restarts game */}
<button
className="mt-10 w-1/2 border-2 border-indigo-800 p-3 text-indigo-800 rounded-xl cursor-pointer transition-all hover:bg-yellow-500 hover:border-yellow-500 hover:text-white"
onClick={() => {
Expand All @@ -106,6 +115,7 @@ const Main = ({
</button>
</div>
) : (
/* Question part of card */
<>
<img
aria-hidden="true"
Expand Down

0 comments on commit 154e235

Please sign in to comment.