How can I get the error message on a good way to solve? Error message: timetotal is not defined开发者_StackOverflow.
$(document).ready(function() {
if (typeof(timeleft) !== 'undefined') {
Chrono.update();
}
$('a.add_other_answer').click(function() {
addAnswer();
});
});
Chrono = {
warning: timetotal * 0.25,
critical: timetotal * 0.05,
update: function() {
...
...
This seems pretty self-explanatory, even with your code example being incomplete.
timetotal
is most likely undefined at this line, since it is passed as a property of the object Chrono
:
warning: timetotal * 0.25,
You are most likely incrementing timetotal
in your Chrono.update
method, but that is too late: the property should have an initial value if you want to multiply it with 0.25
or 0.05
.
Solution:
var timetotal = 0;
Chrono = {
warning: timetotal * 0.25,
critical: timetotal * 0.05,
精彩评论