Getting started with Textual: A detailed guide on setting up your first stopwatch

Posted by

Textual Stopwatch Tutorial 01 – Textual Setup

Textual Stopwatch Tutorial 01 – Textual Setup

Welcome to the first tutorial in our series on creating a textual stopwatch. In this tutorial, we will be setting up the basic structure of our stopwatch using HTML and CSS.

Step 1: HTML Setup

First, let’s create the basic HTML structure for our stopwatch. We will have a heading for the title, a div for displaying the time, and buttons for starting, stopping, and resetting the stopwatch.

“`html

Textual Stopwatch

00:00:00



“`

Step 2: CSS Styling

Next, let’s add some CSS styling to make our stopwatch look more visually appealing. We will style the text display, buttons, and overall layout of the stopwatch.

“`html

body {
font-family: Arial, sans-serif;
}

div {
text-align: center;
margin-top: 20px;
}

#timer {
font-size: 24px;
margin-bottom: 10px;
}

button {
padding: 5px 10px;
margin: 0 5px;
font-size: 16px;
}

“`

Step 3: JavaScript Functionality

Finally, we will need to add some JavaScript to make our stopwatch functional. We will create functions for starting, stopping, and resetting the stopwatch.

“`html

let timer;
let time = 0;
let isRunning = false;

function displayTime() {
const hours = Math.floor(time / 3600);
const minutes = Math.floor((time % 3600) / 60);
const seconds = Math.floor(time % 60);

document.getElementById(“timer”).textContent = `${hours}:${minutes}:${seconds}`;
}

function startTimer() {
if (!isRunning) {
isRunning = true;
timer = setInterval(() => {
time++;
displayTime();
}, 1000);
}
}

function stopTimer() {
clearInterval(timer);
isRunning = false;
}

function resetTimer() {
clearInterval(timer);
isRunning = false;
time = 0;
displayTime();
}

document.getElementById(“start”).addEventListener(“click”, startTimer);
document.getElementById(“stop”).addEventListener(“click”, stopTimer);
document.getElementById(“reset”).addEventListener(“click”, resetTimer);

“`

That’s it! You now have a fully functional textual stopwatch setup using HTML, CSS, and JavaScript. Feel free to customize the styling and functionality further to suit your needs.

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@GrantMcLean
8 months ago

Thanks Rodrigo. I enjoyed this video series and looking forward to the final instalment(s) 🙂. I like your teaching style and I'm loving the textual framework.

@jorgeluizplautz6890
8 months ago

Thanks Rodrigo. It is a very good live. The lib is fantastic.

@sants9383
8 months ago

parabens rodrigo, ótimo video. Essa lib é sensacional