设计和编写一个程序,提示用户他们的出生年份,计算用户的年龄并显示用户的年龄。如果用户的年龄超过 40 岁,则将网页的背景颜色设置为红色。该解决方案必须使用 JavaScript Date 对象并使用程序员创建的函数来计算用户的年龄。
非常小的问题,如果年龄超过 40 岁,我只需要让屏幕变红我似乎无法做到这一点......
<html>
<head>
<title> Age of person </title>
<div id="age"></div>
<body>
<script>
function determine_age_of_person ( year )
{
var today = new Date();
var now_year = today.getFullYear();
var age = now_year - year_person_was_born;
return age;
}
var year_person_was_born;
//unsure about below statement the '==' part
var age_of_person==age;
do
{
year_person_was_born = prompt("Enter year you were born", "");
year_person_was_born = parseInt (year_person_was_born1 );
}
while (is(year_person_was_born));
age_of_person = determine_age_of_person ( year_person_was_born );
if (age_of_person>40)
document.body.style.backgroundColor = "red";
else
document.body.style.backgroundColor = "white";
document.getElementById("age").innerHTML = "You are " + age_of_person + " years old";
</script>
</body>
</html>