hello I am facing a little problem with using javascript with HTML, I have created a small form just for learning purpose, the thing I want to do is if the user checks the checkbox with id=“programmer” then an alert will appear on screen giving a greeting that “Wow, you are also a programmer like me!!” but it doesn’t seem to work. I have never encountered DOM elements with HTML & JS, it’s my first try so it would be nice if you could help me
This is the HTML code with tag containing JS code -
<!DOCTYPE html>
<html>
<head>
<title>Slam Book</title>
</head>
<body style="background-color: rgba(2, 29, 29, 0.884); font-family: 'Segoe UI', Tahoma, sans-serif; font-weight: 600;">
<h2>Tell us something about you</h2>
<form>
First Name:   <input type="text" name="firstNameField" value="Enter your first name" size="20"><br>
Last Name:   <input type="text" name="lastNameField" value="Enter your last name" size="20"> <br>
</form>
<p>Enter your age</p>
<input type="number" name="ageField" value="Enter your age">
<p>Enter your password</p>
<input type="password" name="pass" maxlength="25">
<p>Tell us more about you</p>
<textarea type="comments" cols="43" rows="10">write here...</textarea>
<p>Select your favourite color</p>
<select name="colorChoose" size="4">
<option selected>Red
<option>Blue
<option>Green
<option>Yellow
<option>Orange
<option>Brown
<option>Black
<option>Purple
<option>Pink
</select>
<p>Tell us your profession</p>
<input type="radio" name="r1" value="student" checked>Student  
<input type="radio" name="r1" value="teacher">Teacher  
<input type="radio" name="r1" value="doctor">Doctor  
<input type="radio" name="r1" value="programmer">Programmer
<p>Tell us your hobbies</p>
<input type="checkbox" name="c1" value="cricket" checked>Cricket  
<input type="checkbox" name="c1" id="programmer" value="programming">Programming  
<input type="checkbox" name="c1" value="football">Football  
<input type="checkbox" name="c1" value="music">Music <br>
<p>Tell something more about you in a .txt file and attach it here</p>
<input type="file" name="file1" accept=".txt">
<form>
<p>
<input type="submit" value="submit">
<input type="reset" value="reset">
</p>
</form>
<script>
if (document.getElementById("programmer").checked) {
alert("Wow, you are also a programmer like me!!");
}
</script>
</body>
</html>
Hope you can help. Thanks!!