HTML codes for creating Form, Arrays and using typewrite
NOTE: This file marks the end of this chapter.
Form--------------------→
<!DOCTYPE html> <!-- Tells the browser this is an HTML5 file -->
<html>
<head>
<title>Form Example</title> <!-- Title shown on browser tab -->
</head>
<body>
<!-- Form starts -->
<form>
<!-- Textbox -->
<label>Full Name:</label> <!-- Label = text in front of input -->
<input type="text"> <!-- Textbox to type name -->
<br><br> <!-- Line break -->
<!-- Password -->
<label>Password:</label>
<input type="password"> <!-- Password field (hides text) -->
<br><br>
<!-- Radio buttons -->
<p>Select Gender:</p> <!-- Heading for group -->
<input type="radio" name="gender"> Male <!-- Radio button for Male -->
<input type="radio" name="gender"> Female <!-- Radio button for Female -->
<br><br>
<!-- Checkboxes -->
<p>Choose Hobbies:</p>
<input type="checkbox"> Sports <!-- Checkbox for Sports -->
<input type="checkbox"> Music <!-- Checkbox for Music -->
<br><br>
<!-- Buttons -->
<button type="submit">Submit</button> <!-- Submit button -->
<button type="reset">Reset</button> <!-- Reset button clears form -->
</form>
<!-- Form ends -->
</body>
</html>
Array---------------→
<!DOCTYPE html>
<html>
<head>
<title>Typecasting and Arrays</title>
</head>
<body>
<script>
// ----- Arrays -----
let arr = []; // empty array
// Take input for 3 elements
for (let i = 0; i < 3; i++) {
arr[i] = prompt("Enter value for element " + (i+1) + ":");
// Display array elements
[Link]("Array Elements:<br>");
for (let i = 0; i < [Link]; i++) {
[Link]("Element " + (i+1) + ": " + arr[i] + "<br>");
</script>
</body>
</html>
Typewrite------------→
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>JavaScript: Typecasting and Arrays</h2>
<script>
// ----- Implicit Typecasting (automatic) -----
let num = 10; // number
let str = "5"; // string
let result = num + str; // number + string → becomes string automatically
[Link]("Implicit Casting (10 + '5') = " + result + "<br>");
// Output will be "105" (string)
// ----- Explicit Typecasting (manual) -----
let strNum = "20"; // string
let convertedNum = Number(strNum); // String → Number
let sum = convertedNum + 5;
[Link]("Explicit Casting (Number('20') + 5) = " + sum + "<br>");
// Output will be 25 (number)
let numberValue = 100;
let stringValue = String(numberValue); // Number → String
[Link]("Explicit Casting (String(100)) = " + stringValue + "<br>");
// Output will be "100" (string)
[Link]("<hr>");
</script>
</body>
</html>