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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ This project includes a `src/components` folder containing several React compone

### Task 1: Project Set Up

- [ ] Create a forked copy of this project.
- [ ] Clone your OWN fork of the repository using your terminal.
- [ ] CD into the project base directory.
- [ ] Download project dependencies by running `npm install`.
- [ ] Start up the app using `npm start`.
- [ ] Optionally run tests using `npm test`. (The app must be running on `http://localhost:1234`)
- [ ] Push commits: `git push origin main`.
- [X] Create a forked copy of this project.
- [X] Clone your OWN fork of the repository using your terminal.
- [X] CD into the project base directory.
- [X] Download project dependencies by running `npm install`.
- [X] Start up the app using `npm start`.
- [X] Optionally run tests using `npm test`. (The app must be running on `http://localhost:1234`)
- [X] Push commits: `git push origin main`.

### Task 2a: Minimum Viable Product

Expand Down Expand Up @@ -62,4 +62,4 @@ The move by the computer should probably be random if the previous checks turn o

## Submission Format

- [ ] Submit a link to your repo in canvas.
- [X] Submit a link to your repo in canvas.
1 change: 1 addition & 0 deletions package-lock.json

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

26 changes: 19 additions & 7 deletions src/components/Counter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
COUNTER Instructions

Expand Down Expand Up @@ -46,38 +47,49 @@ STEP 6:
This click handler needs to use 'setCount' to set the 'count' to be zero again.
*/

import React from 'react'; /* STEP 0 */

import React, { useState } from 'react'; /* STEP 0 */




export default function Counter() {
/* STEP 1 */
const [count, setCount] = useState(0)

const increment = () => {

setCount(count + 1);
/* STEP 4 */
};
const decrement = () => {
setCount(count - 1);
/* STEP 5 */
};
const reset = () => {
setCount(0);
/* STEP 6 */
};

const style = {
fontSize: '1.5em',
marginBottom: '0.3em',
color: 'royalblue', /* STEP 2 */
color: count % 2 === 0 ? 'royalblue': 'crimson' /* STEP 2 */
};

return (
<div className='widget-counter container'>
<h2>Counter</h2>
<div id='count' style={style}>
Number 0 is even {/* STEP 3 */}
Number { count } is { count % 2 === 0 ? 'even' : 'odd' } {/* STEP 3 */}
</div>
<div>
<button id='increment' onClick={increment}>Increment</button>
<button id='decrement' onClick={decrement}>Decrement</button>
<button id='resetCount' onClick={reset}>Reset</button>
<button id='increment' onClick={() => setCount(count + 1)}>Increment</button>
<button id='decrement' onClick={() => setCount(count - 1)}>Decrement</button>
<button id='resetCount' onClick={() => setCount(0)}>Reset</button>
</div>
</div>
);
}

}

12 changes: 7 additions & 5 deletions src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,36 @@ STEP 6:
We need to add an extra prop to the <input /> element like so: value={inputValue}
*/

import React from 'react'; /* STEP 0 */
import React, { useState } from 'react'; /* STEP 0 */

export default function Input() {
/* STEP 1 */
const [inputValue, setInputValue] = useState('');

const changeInput = evt => {
// When the input changes, its whole value can be found inside the event object.
// Log out the synthetic event object 'evt' and see for yourself.
const { value } = evt.target;

setInputValue(value);
/* STEP 4 */
};
const reset = () => {
/* STEP 5 */
setInputValue('');
};

const style = {
fontSize: '1.5em',
marginBottom: '0.3em',
color: 'royalblue', /* STEP 2 */
color: inputValue.length > 10 ? 'crimson' : 'royalblue', /* STEP 2 */
};

return (
<div className='widget-input container'>
<h2>Input</h2>
<div id='output' style={style}></div> {/* STEP 3 */}
<div id='output' style={style}>{inputValue.toUpperCase()}</div> {/* STEP 3 */}
<div>
<input id='input' type='text' onChange={changeInput} /> {/* STEP 6 */}
<input id='input' type='text' onChange={changeInput} value={inputValue} /> {/* STEP 6 */}
<button id='resetInput' onClick={reset}>Reset</button>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Moods.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,39 @@ STEPS 4, 5, 6:
Inside these click handlers set the correct mood, using 'setMood' and the variables below the imports.
*/

import React from 'react'; /* STEP 0 */
import React, { useState } from 'react'; /* STEP 0 */

const initialMood = 'Not sure how I feel';
const happyMood = 'Quite happy!';
const sadMood = 'Rather sad';

export default function Moods() {
/* STEP 1 */
const [mood, setMood] = useState(happyMood);

const makeHappy = () => {
/* STEP 4 */
setMood(happyMood);
};
const makeSad = () => {
/* STEP 5 */
setMood(sadMood);
};
const reset = () => {
/* STEP 6 */
setMood(initialMood);
};

const style = {
fontSize: '1.5em',
marginBottom: '0.3em',
color: 'crimson', /* STEP 2 */
color: mood === happyMood ? 'royalblue' : 'crimson', /* STEP 2 */
};

return (
<div className='widget-moods container'>
<h2>Moods</h2>
<div id='mood' style={style}>Not sure how I feel</div> {/* STEP 3 */}
<div id='mood' style={style}>{ mood }</div> {/* STEP 3 */}
<div>
<button id='makeHappy' onClick={makeHappy}>Make Happy</button>
<button id='makeSad' onClick={makeSad}>Make Sad</button>
Expand Down
11 changes: 7 additions & 4 deletions src/components/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ STEP 4:
Do you remember the operator we use to do "not"?
*/

import React from 'react'; /* STEP 0 */
import React, { useState } from 'react'; /* STEP 0 */

export default function Spinner() {
/* STEP 1 */
const [spinnerOn, setSpinnerOn] = useState(true);

const toggleSpinner = () => {
/* STEP 4 */
/* STEP 4 */
setSpinnerOn(!spinnerOn);

};

return (
<div className='widget-spinner container'>
<h2>Spinner</h2>
{
true && <div id='spinner' className='spinner'>--+--</div> /* STEP 2 */
spinnerOn && <div id='spinner' className='spinner'>--+--</div> /* STEP 2 */
}
<button id='toggleSpinner' onClick={toggleSpinner}>
Hide Spinner {/* STEP 3 */}
{ spinnerOn ? 'Hide' : 'Show' } {/* STEP 3 */}
</button>
</div>
);
Expand Down
11 changes: 8 additions & 3 deletions src/components/Squares.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Only one square (or none) can be active at any given point.
Find comments below to help you along.
*/

import React from 'react';
import React, { useState } from 'react';

// Use this variable ONLY to initialize a slice of state!
const listOfSquareIds = ['sqA', 'sqB', 'sqC', 'sqD'];
Expand All @@ -24,20 +24,25 @@ export default function Squares() {
// 'activeSquare'. One holds the _array_ of square ids, and the other keeps track
// of the currently active square. On page load there's no active square,
// so the value of 'activeSquare' should be null.
const [squares, setSquares] = useState(listOfSquareIds);
const [activeSquare, setActiveSquare] = useState(null);

const getClassName = id => {
// This is NOT a click handler but a helper, used inside the JSX (see below).
// It should return a string containing the class name of 'active', if the id passed
// as the argument matches the active square in state, empty string otherwise.
// Right-click and "inspect element" on the square to see its effect.
return ''
return id === activeSquare ? 'active' : '';
};

const markActive = id => {
// This is a helper used inside an _inlined_ click handler (see below).
// Set the id argument to become the active id in state
// (unless it already is, in which case we should reset
// the currently active square id back to initial state).
if (id === activeSquare){
setActiveSquare(null);
}else {setActiveSquare(id)}
};

return (
Expand All @@ -48,7 +53,7 @@ export default function Squares() {
// Nasty bug! We should map over a slice of state, instead of 'listOfSquareIds'.
// We might say: "it works, though!" But if the list of squares is not state,
// we could never add squares, change squares or remove squares in the future. Fix!
listOfSquareIds.map(id =>
squares.map(id =>
<div
id={id}
key={id}
Expand Down