Front End Web Development Assignments (2)
Front End Web Development Assignments (2)
Write a script that shows an alert box with the message: "Welcome to JavaScript!"
15. Add Two Numbers
Write a script that takes two numbers as input from the user (using prompt), adds them, and
displays the result in an alert box.
Solution
1. Create a Basic Webpage
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="Sample Image" width="300">
</body>
</html>
2. Hyperlinks
<html>
<body>
<a href="https://www.google.com" target="_blank">Visit Google</a><br>
<a href="page2.html">Go to Page 2</a><br>
<a href="#section1">Go to Section 1</a>
3. Lists
<html>
<body>
<h3>Favorite Fruits</h3>
<ol>
<li>Apple</li>
<li>Banana</li>
<li>Citrus
<ul>
<li>Orange</li>
<li>Lemon</li>
</ul>
</li>
</ol>
</body>
</html>
4. Forms
<html>
<body>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label><br><br>
5. Tables
<html>
<body>
<table border="1">
<tr>
<th>Day</th>
<th>Subject</th>
<th>Time</th>
</tr>
<tr>
<td>Monday</td>
<td>Math</td>
<td>10:00 AM</td>
</tr>
<tr>
<td>Tuesday</td>
<td>Science</td>
<td>11:00 AM</td>
</tr>
</table>
</body>
</html>
<html>
<body>
<a href="https://www.example.com">
<img src="example.jpg" alt="Example Image" width="200">
</a>
</body>
</html>
7. Semantic HTML
<html>
<body>
<header>
<h1>Website Header</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
<section>
<article>
<h2>Article Title</h2>
<p>This is an article.</p>
</article>
</section>
<footer>
<p>Website Footer</p>
</footer>
</body>
</html>
<html>
<body>
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support audio playback.
</audio>
<html>
<body>
<form>
<label for="name">Name:</label>
<input type="text" id="name"><br><br>
<html>
<head>
<style>
h1 { color: blue; }
p { font-size: 14px; }
</style>
</head>
<body>
<h1>Styled Heading</h1>
<p>Styled Paragraph</p>
</body>
</html>
12. Selectors
<html>
<head>
<style>
p { color: green; }
#special { color: red; }
.highlight { background-color: yellow; }
</style>
<p>This is a paragraph.</p>
<p id="special">This is a special paragraph.</p>
<p class="highlight">This is a highlighted paragraph.</p>
</body>
</html>
13. Color and Backgrounds
<html>
<head>
<style>
body { background-color: lightblue; }
h1 { color: white; }
div { background: linear-gradient(to right, red, yellow); }
</style>
</body>
</html>
<html>
<head>
<title>Alert Box</title>
</head>
<body>
<script>
alert("Welcome to JavaScript!");
</script>
</body>
</html>
<html>
<head>
<title>Add Two Numbers</title>
</head>
<body>
<script>
let num1 = parseFloat(prompt("Enter the first number:"));
let num2 = parseFloat(prompt("Enter the second number:"));
let sum = num1 + num2;
alert("The sum is: " + sum);
</script>
</body>
</html>