Skip to content

Commit 69df0c4

Browse files
author
justintsugranes
committed
initial commit
0 parents  commit 69df0c4

12 files changed

Lines changed: 29738 additions & 0 deletions

File tree

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Guess The Number - Creating Dynamic Events in React
2+
3+
## Task
4+
5+
1. This task's starting point is the App component's h1 element that reads: "Task: Add a button and handle a click event". As a first step in this task, you'll need to add a button element, with an opening and a closing button tag.
6+
2. In between the opening and closing button tags, add the following text: `Guess the number between 1 and 3`.
7+
3. Inside the opening button tag, add the onClick event-handling attribute, and pass it the following JSX expression: `{handleClick}`.
8+
4. Above the return statement of the App component - but still inside the App function - add the following ES5 function declaration:
9+
10+
```js
11+
function handleClick() {
12+
let randomNum = Math.floor(Math.random() * 3) + 1
13+
console.log(randomNum)
14+
let userInput = prompt('type a number')
15+
alert(`Computer number: ${randomNum}, Your guess: ${userInput}`)
16+
}
17+
```
18+
19+
5. Save your changes and run the app. Preview it in the browser. You should be able to click a button, which will trigger the handleClick function. The handleClick function will in turn show a prompt pop up which you can type into. After you've finished, an alert pop up will show computer's "choice" and your guess. After you click "ok" to close the alert, you'll be able to click the button again and try matching the number that the computer "chose" again.
20+
21+
## About this React app
22+
23+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
24+
25+
## Setup
26+
27+
1. Open the built-in terminal
28+
2. Run `npm install` to add the `node_modules` folder
29+
3. Run `npm start`
30+
4. Click the "Open Development server" in the bottom status bar to view the running react app in the browser.

0 commit comments

Comments
 (0)