If you want to practice JavaScript with a tiny but useful project, a weight converter is a good place to start.
In this example, we will build a simple kilograms to grams converter using basic HTML, CSS, and JavaScript.
The logic is straightforward:
1 kilogram = 1000 grams
So the formula is:
grams = kilograms × 1000
Step 1: Create the HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kilograms to Grams Converter</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 500px;
margin: 40px auto;
padding: 20px;
}
.converter {
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
input, button {
width: 100%;
padding: 10px;
margin-top: 10px;
font-size: 16px;
}
.result {
margin-top: 15px;
font-weight: bold;
Discussion
Be the first to comment
Add your perspective to get the discussion started.