Skip to content

Commit 3d32bbb

Browse files
committed
Add seconds variable and fix some code
1 parent 232330a commit 3d32bbb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/App.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ function App() {
77
const [pointsPerSecond, setPointsPerSecond] = useState(0);
88
const [clicks, setClicks] = useState(0); //set initial clicks pressed to 0
99
const [clickMultiplier, setClickMultiplier] = useState(1);
10+
const [seconds, setSeconds] = useState(0); //set initial seconds played to 0
1011
useEffect(() => {
1112
const interval = setInterval(() => {
1213
//increase points every second
13-
setPoints(points + pointsPerSecond);
14+
setPoints(points + pointsPerSecond); //increase points by points per second
15+
setSeconds(seconds + 1); //add 1 second
1416
}, 1000);
1517
return () => {
1618
clearInterval(interval); //clear interval when component unmounts
@@ -29,7 +31,7 @@ function App() {
2931
function addPointsFromClick() {
3032
//add points from clicking a button
3133
setPoints(points + clickMultiplier); //increase points by 1 when button clicked
32-
setClicks(clicks + clickMultiplier); //increase clicks made by 1
34+
setClicks(clicks + 1); //increase clicks made by 1
3335
}
3436
function upgradeClicker() {
3537
//upgrade clicker (points per click)

0 commit comments

Comments
 (0)