这里的目标是,当我在文本框中输入一个值时,它会根据你之间的年份为你分配一个标题。但是,它不起作用,JSFiddle 给了我以下错误:
"<a class='gotoLine' href='#48:26'>48:26</a> Uncaught SyntaxError:
Unexpected token '<='"
据我所知,这甚至不应该是一个错误。小于或等于的符号是<=所以我不确定问题是什么。
function ShowGeneration() {
var yearBorn;
var generation;
var Boomer
var X
var Millenial
var Z
yearBorn = parseFloat(document.getElementById('yearBox').value);
// insert if statements here to map yearBorn onto generation
if (yearBorn >= 1944 && yearBorn <= 1964)
generation = Boomer;
else {
if (yearBorn >= 1965 && yearBorn <= 1979)
generation = X;
else {
if (yearBorn >= 1980 && yearBorn <= 1994)
generation = Millenial;
else {
if (yearBorn >= 1995 && yearBorn <= 2015)
generation = Z;
}
}
}
document.getElementById('outputDiv').innerHTML = "You belong to the " + generation + " generation.";
}
<p>
What year were you born? <input type="text" id="yearBox" size="6">
</p>
<input type="button" value="Click for Generation" onclick="ShowGeneration();">
<div id="outputDiv"></div>