Skip to content
Open
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
20 changes: 8 additions & 12 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@ import { useState } from 'react';
import './App.scss';

export const App = () => {
const [count] = useState(0);

const [count, setCount] = useState(0);
const addOne = () => {
// write code here
setCount(prev => prev + 1);
};

const add100 = () => {
// write code here
setCount(prev => prev + 100);
};

// DON'T change the code below
const increase = () => {
if (count % 5 === 0) {
add100();
}
setCount(prev => {
const shouldAdd100 = prev % 5 === 0; // Check divisibility on the original count
const incremented = prev + 1; // Add 1 to the count

addOne();
return shouldAdd100 ? incremented + 100 : incremented; // Add 100 if original count was divisible by 5
});
};

return (
<div className="App">
<h1 className="App__title">{`Count: ${count}`}</h1>

<button type="button" className="App__add-one" onClick={addOne}>
Add 1
</button>

<button type="button" className="App__add-100" onClick={add100}>
Add 100
</button>

<button type="button" className="App__increase" onClick={increase}>
Increase
</button>
Expand Down