Skip to content
Open
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
49 changes: 0 additions & 49 deletions code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added code/public/animals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</head>

<body>
<img class="animals"src="./animals.png" alt="">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
Expand Down
91 changes: 87 additions & 4 deletions code/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,92 @@
import React from 'react';
/* eslint-disable max-len */
import React, { useState } from 'react';
import { Name } from './components/Name';
import { Prefer } from './components/Prefer';
import { Color } from './components/Color';
import { Thing } from './components/Thing';
import { QuizResult } from './components/QuizResult'
import './index.css';
import './reset.css';

export const App = () => {
const [counter, setCounter] = useState(0);
const [name, setName] = useState('')
const [prefers, setPrefers] = useState('')
const [color, setColor] = useState('')
const [things, setThing] = useState('')
const [results, setResults] = useState('')
const [started, setStarted] = useState(false);

const handleNextStep = () => {
console.log('counter before', counter);
setCounter(counter + 1);
console.log('after', counter)
};
const handleStartQuiz = () => {
setStarted(true);
handleNextStep();
Comment on lines +25 to +27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice using a starter function!

/* if (counter >= 5) {
setQuizEnded(true);
} */
Comment on lines +28 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove code that is commented out if it's not needed

};
const showResult = (
<QuizResult name={name} results={results} />
)
return (
<div>
Find me in src/app.js!
</div>
<main className="StartPage">
{!started && (
<header className="start-container">
<h1>Answer these questions and we will tell you your favourite animal</h1>
<button type="button" onClick={handleStartQuiz} className="startBtn" aria-label="press button to start the quiz">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of Aria labels

Start quiz
</button>
</header>
)}

{counter === 1 && (
<div>
<Name name={name} setName={setName} counterFromApp={counter} setCounter={setCounter} />

</div>)}
Comment on lines +47 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look into if a div is needed here


{counter === 2 && (
<Prefer prefers={prefers} setPrefers={setPrefers} counterFromApp={counter} setCounter={setCounter} />
)}
{counter === 3 && (
<Color color={color} setColor={setColor} counterFromApp={counter} setCounter={setCounter} />
)}
{counter === 4 && (
<Thing thing={things} setThing={setThing} counterFromApp={counter} setCounter={setCounter} />
)}
{counter >= 5 && (
<QuizResult name={name} color={color} prefer={prefers} thing={things} results={results} setResults={setResults} QuizResult={QuizResult} />
)}

{(counter === 1 && !name)
|| (counter === 2 && !prefers)
|| (counter === 3 && !color)
|| (counter === 4 && !things) ? (
<p className="answer">Please answer the current question before proceeding.</p>
Comment on lines +65 to +69
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there could be either just a comment here or it could be turned into a function that explains it's purpose

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job having a reminder here to answer the question before even showing the next-button. Really impressed!

)
|| (counter === 5 && !showResult)
: (
started && counter < 5 && (
<button type="button" onClick={handleNextStep} className="nextQuestion" aria-label="press next question button after inserting your name">
Next question
</button>
)
)}
</main>
);
}
// start button hur ska jag sätta button nr 2 vart?
// what should i put in result to show my results
// where should I put my if statement
// how do I make next question just show from name...
// what is exactly happening in line 30 & 55
/* {started && counter < 5 && (
<button type="button" onClick={handleNextStep} className="nextQuestion">
Next question
</button> */
// why like this in nr 59 what does it mean?

36 changes: 36 additions & 0 deletions code/src/components/Color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'

export const Color = ({ color, setColor, counterFromApp, setCounter }) => {
const handleColorChange = (event) => {
setColor(event.target.value);
setCounter(counterFromApp + 1);
console.log('Color picked: ', event.target.value);
}
console.log(color)
return (
<div className="color">
<h2>What´s your favourite color ?</h2>
<form className="favouriteColor" id="color-selector">
<button
className="pink"
type="button"
onClick={handleColorChange}
value="pink"
aria-label="Select Pink color"
title="Select Pink color" />

<button
className="black"
type="button"
onClick={handleColorChange}
value="black"
aria-label="Select Black color"
title="Select Black color" />

</form>

</div>
);
}

// what should I have as a value to get the if statements right?
20 changes: 20 additions & 0 deletions code/src/components/Name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

export const Name = ({ name, setName, counter }) => {
const handleNameChange = (event) => {
setName(event.target.value);

console.log('Name:', event.target.value);
}

return (
<div className="name-container">
<p>What is your name?</p>
<form>
<section className="inputName">
<input className="inputClass" type="text" onChange={handleNameChange} value={name} counter={counter} aria-labelledby="name-label" arial-label="Write your name here and then press button further down" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of aria-labels. Think about the className for this input, and if it could be re-named to something more unique to this specific input/component

</section>
</form>
</div>
);
}
24 changes: 24 additions & 0 deletions code/src/components/Prefer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'

export const Prefer = ({ prefers, setPrefers, counterFromApp, setCounter }) => {
const handlePreferChange = (event) => {
setPrefers(event.target.value);
setCounter(counterFromApp + 1);
console.log('prefers: ', event.target.value);
}

return (
<div className="whatDoYou">
<h2>Select your preferred activity</h2>
<section className="dropDown">

<select className="dropMenu" onChange={handlePreferChange} value={prefers} aria-label="Select your preferred activity">
<option value="" className="choose"> Choose an option</option>
<option value="books" className="books">Books & plants 🪴📚</option>
<option value="surf" className="surf">Surf &palmtrees 🏄🏿‍♀️ 🏝️</option>
<option value="people" className="people">People, fika & walks 👨🏻‍🦽🚶🏾‍♀️</option>
Comment on lines +17 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cute addition with the emojis

</select>
</section>
</div>
)
}
Loading