I'm trying to create a simple program that will assign a number (riskLevel) based on the amount of experience (totalTime) a person has and input it all into a quick table in HTML.
I am having a problem with the this.riskLevel value. I am trying to have it take the totalTime value and use an if/else statement to assign an integer to riskLevel.
When I call the getCrewmember() function (using the submit button) the firstName, lastName, and totalTime, all populate correctly in the HTML table. The riskLevel doesnt, it just writes out the entire code for the function.
What am I doing wrong? Also, I want to be able to input a name into the html text input field, and have that person's name come up in the program. How can I tell the getCrewmember() function to take the value that is entered into the text feild?
Here is the code:
function pilot(firstName, lastName, totalTime){
this.firstName=firstName;
this.lastName=lastName;
this.totalTime=totalTime;
this.riskLevel=function(){
if(this.totalTime >= 1000){
riskLevel = 1;
}else if(this.totalTime >=500){
riskLevel = 2;
}else if(this.totalTime >= 250){
riskLevel = 3;
}
}
}
var jdoe = new pilot("Jon", "Doe", 480)
function getCrewmember(){
document.getElementById("firstName").innerHTML = jdoe.firstName;
document.getElementById("lastName").innerHTML = jdoe.lastName;
document.getElementById("totalHours").innerHTML = jdoe.totalTime;
document.getElementById("riskLevel").innerHTML = jdoe.riskLevel;
}
</script>
<table>
<thead>
<th>First</th>
<th>Last</th>
<th>Total Hours</th>
<th>Risk Level</th>
</thead>
<tr>
<td id="firstName">First Name</td>
<td id="lastName">Last Name</td>
<td id="totalHours">Total Hours</td>
<td id="riskLevel">Risk Level</td>
</tr>
<tr>
<td><input type="text" id="textField"></td>
</tr>
<tr>
<td><input type="submit" value="Get Crewmember" onclick="getCrewmember()"></td>
</tr>
</table>
jdoe.riskLevel(), and you want toreturn 1|2|3;instead of assigning torisklevel