32/33 unidentified var or unidentified id


#1

My solution looks right to me however when I submitted it as is it gives me an error saying "unidentified var" and when I remove it, it says "unidentified id"

// 3 lines required to make harry_potter
var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";

// A custom constructor for book
function Book (pages, author)

var the_hobbit = new Book(320 ,"Tolkien");


#2

Okay. Your function is the problem. Observe:

Here you don't have anything inside your function. So let's talk functions!
<><><><><><><><><><><><><><><>Functions<><><><><><><><><><><><><><><><>
The basic formula for a function is this:

var functionName = function(arguments) {
do something here
}
To call a function, it looks like this.functionName(arguments);
Now, let's talk about each of these elements in turn. First, you have to make your function's name. Simple, and the standard way to name it is one word made of two, the second capitalized. Next is what makes your function, well, a function. Telling the computer that it's a function is just the word "function" before your arguments. Hold up-- what's an argument? This is a temporary "variable" you will "declare" when you call the function. It tells the computer the things it will need to know in order to run the function. For example, in this function, the only argument is "price". The price is, as I said, what the computer needs to know in order to run the function. If it didn't know what "price" was, then it wouldn't have any numbers to run the function with. The key here is thinking like the computer.
The next part is simple. You tell the computer what you want it to do. For example, here you want it to multiply the price of the oranges by five and print that out onto the console, so you'd type:
console.log(price*5) as you did. Also, it's never a bad idea to add a semicolon after console.log. Then, you close what you want to do with the curly brackets.
Finally, calling the function. Make sure you call the function outside of the function. How you do it is: first, you type in which function you want to call, then declare your argument "variables" in parentheses. Here, the orange cost is 5, so you type in 5 in the parentheses obviously. A semicolon finishes your calling, and -- Voila! A function!
Hope it helped.


#3

This was for another question on functions... Sorry about the "as you did"s and stuff... Still hope it helped.


#4

your supposed to create a constructor function in this case;

// 3 lines required to make harry_potter
var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";

// A custom constructor for book
function Book (pages, author){ <------This is how a construct looks like;
this.pages= pages;
this.author = author;
}

var the_hobbit = new Book(320 ,"Tolkien");

console.log(the_hobbit.pages); <------Test your construction function and see if it works.


#6

Thanks for the help! Ive still been trying to adjust it to my solution which still isnt working it looks like this // 3 lines required to make harry_potter
var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";

// A custom constructor for book
function Book (pages, author)
{
this.pages= pages;
this.author = author;
}
var the_hobbit = new Book(320 ,"Tolkien");


#7

I hadn't typed out the whole name "J.R.R Tolkien" thanks for the help!


#8

Oh. You're welcome! A simple mistake like that... I can't blame you for missing it. I hope you didn't mind that LLLLLLLLOOOOOOONNNNNNNGGGGG post. :sweat_smile: :smile: Glad you figured it out.


#9

This worked out for me!, after some debugging..


#11

It is correct

var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";
function Book (pages, author)
{
this.pages= pages;
this.author = author;
}
var the_hobbit = new Book(320 ,"J.R.R. Tolkien");