I am in school for software engineering and not brand new but still a student of the field with a lot to learn and was wondering if someone could tell me if I was just making a newbie mistake. I had a homework assignment in my html and JavaScript class to make a page that someone could enter there name, age and prompt a background color change through JavaScript. I was able to do the assignment but after the alert to tell you your name, age and what color the background was turned to (at this point the background is the color you put in) it resets the form/page. I do not know why it is doing this and neither does anyone else in my class so I was wondering if anyone could tell me why it is resetting and if it is something I did in the code so I can watch out for it in the future.
<!DOCTYPE html>
<html>
<head>
<script>
function getInformation() {
var strColor = prompt("What is your favorite color");
var strFirstName = document.getElementById("txtName").value;
var strYourAge = document.getElementById("txtAge").value;
document.body.style.backgroundColor= strColor;
alert(strFirstName + "Your favorite background color was applied to the backgrond of the page. \n\n and your age is" + strYourAge);
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td><label>First Name</label>
</tr>
<tr>
<td><input id="txtName" type="text" name="Name" required></td>
</tr>
<tr>
<td><label>Your Age</label></td>
</tr>
<tr>
<td><input id="txtAge" type="number" name="Age" required></td>
</tr>
<tr>
<td><button onclick="getInformation()">Submit</button></td>
</tr>
</table>
</form>
</body>
</html>