0

How can I get the error message on a good way to solve? Error message: timetotal is not defined.

 $(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() {
    ...
    ...
2
  • We need some more code, where is timetotal defined? Commented Apr 14, 2011 at 9:43
  • @Wolfy87: It seems it is not ;) @lander: You have to define timetotal somewhere... Commented Apr 14, 2011 at 9:44

1 Answer 1

1

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,
Sign up to request clarification or add additional context in comments.

4 Comments

Edit: I see you got it fixed...;) Edit2: The last example won't work as this will not refer to Chrono but probably to windows. Edit3: This won't work either as Chrono is not defined yet when Chrono.timetotal * 0.25 is executed ;) (there is no way to access a property of an object while defining another property).
@Felix noticed it before your comment and edited my post :) edit: fixed the second error as well now! Doh! :)
Please see the third edit in my comment ;) But +1 from me anyway :)
Haha clearly need another espresso. I'll just remove the second example alltogether and skip JS programming for the day. Thanks for the tips.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.