Build a Calculator -- Error message

non-track-course
build-a-calculator

#1



https://www.codecademy.com/en/courses/web-intermediate-en-jfhjJ/3/3#


Getting this error :Did you define the '.click()' correctly? Look at the hint if you need help

$(document).ready(function(){
    var testNumLength = function(number) {
        if (number.length > 9) {
            totaldiv.text(number.substr(number.length-9,9));
            if (number.length > 15) {
                number = "";
                totaldiv.text("Err");
            }
        } 
    };
    var number = "";
    var newnumber = "";
    var operator = "";
    var totaldiv = $("#total");
    totaldiv.text("0");

    //Add your .click() here!
    $('#numbers a').not('#clear,#clearall').click(function(){
       number += $(this).text();
        totaldiv.text(number);
        testNumLength(number);
    });
});


#2

@tagslayer94943,
The only thing i see is that they ask you to use

number += $(this).html();

in your =click= Eventhandler.

I am having the same error,
even when using as selector

$("#numbers > a")

#3

Hi guys !
I pass it with that:

number += $(this).html(numbers);

Not sure if it's the good answer but it works.

Have a good day .


#4

Thank you so much! This was a big help to me.


#5

You're welcome !
Glad that help you. :slight_smile:


#6

It seems to be some problem though it passes the test.


#7

Hi, can you explain to me why we have to write:

number +=$(this).html(numbers);

and what does += mean?


#8

Hi !
Sorry I don’t remember why this works.

But “number += 2” is the same thing that “number = number + 2”.

With += you can add directly a number (or a string) to your variable.

Maybe that will help you a little ! :slight_smile:


#9

Does that mean I can write number = number + $(this).html(numbers); ?

Btw, thank you for answering my question. That helps me a lot :slightly_smiling_face:


#10

Yes, you can write "number = number + $(this).html(numbers);"
It’s the same thing, just one is shorter than the other.


#11

Thank you…:slightly_smiling_face: