Document. Log(): "Undefined Is Not a Function"

I know, I know, is a common error and you should look at others and blah blah blah. I have and I could not have found a solution.

This is my ENTIRE code.

<div id="div"></div>

<script>
function item(id, price, name, icon){
    this.id = id;
    this.initPrice = 0;
    this.price = price;
    this.name = name;
    this.icon = icon;

    document.getElementById("div").innerHTML += this.name + " = $" + price + " <input id=\"itemNum" + this.id + "\" onchange=\"item" + this.id + ".calc()\" type=\"number\" style=\"width: 40px;\" value=\"1\"></input><br>";

    this.calc = function(){
        document.log("yay");
    }
}

var item1 = new item(1, 700, "Barrel #1", "");
item1.calc();
</script>

I get the error at line 14 and when I change the input I get the same error at line 14 again. What am I doing wrong? How can I fix this?

3

2 Answers

You need to use:

console.log("yay");

instead of:

document.log("yay");

Fiddle Demo

Try console.log() and not document.log()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest