Skip to content

Commit

Permalink
Add timer to room
Browse files Browse the repository at this point in the history
  • Loading branch information
Averyberryman committed Oct 20, 2023
1 parent d390a4e commit c5902fa
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/components/RoomHeader/RoomHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import alien from "../../assets/alien.png";

export default function RoomHeader() {
const [timer, setTimer] = useState(0);
const [isActive, setIsActive] = useState(false);
const [isActive, setIsActive] = useState(true);

useEffect(() => {
let interval;
Expand All @@ -20,22 +20,17 @@ export default function RoomHeader() {
return () => clearInterval(interval);
}, [isActive]);

const startTimer = () => {
setIsActive(!isActive);
};
const minutes = Math.floor(timer / 60);
const seconds = timer % 60;

return (
<header>
<h1>Escape Link</h1>
<img className="alien" src={alien} alt="alien" />
<button onClick={startTimer}>
{isActive ? "Stop Timer" : "Start Timer"}
</button>
<p>
Time Elapsed: {timer.toFixed(2)} seconds
Time Elapsed: {minutes}:{seconds.toFixed(2).padStart(5, "0")}
</p>
</header>
);
}


0 comments on commit c5902fa

Please sign in to comment.