What is wrong with this code?


Hello guys,

I'm taking the beginner's Javascript course and stuck at this code, which actually wasn't written by me:

var my_number = 7; //this has global scope

var timesTwo = function(number) {
my_number = number * 2;
console.log("Inside the function my_number is: ");


console.log("Outside the function my_number is: ")

This is the description along this exercise:
"Change line 4 to use the var keyword. Notice that the value of my_number in the function is now 14 and outside the function is 7.

Using my_number without the var keyword refers to the global variable that has already been declared outside the function in line 1. However, if you use the var keyword inside a function, it declares a new local variable that only exists within that function. "

It gives me this message and I cannot proceed with the course:
"Your code doesn't look quite right. Check the Hint if you need help!
Your code threw the following error: TypeError: console.log is not a

Thank you!

Uknown Error?

It's asking you to re-declare the variable (using the same name) inside the function. This will overwrite the variable in the global scope to a local scope, allowing you to manipulate it without affecting it globally.


Thanks emgo_dev, but I'm not sure what needs to be done, because I get error every time?


That's the most I could really suggest. If you could provide a link to the lesson I could offer more help? I could have sworn that this forum provided a link to the lessons whenever a query like this is made, I can't seem to remember/find it though. It was a great feature.


Here it is:

Thanks a lot!


Your code is nearly identical to mine. Just add the var where it says, and make sure you add a semicolon after the 2nd last console.log().

I'm not getting a console.log isn't a function error when I run your code above.


Thanks a lot emgo_dev!
I refreshed the browser and it worked. I don't have an idea what was the issue.


This error mostly occurs if you use console.log = (...) this overwrites console.log with whatever was in () which leads to the problem that even fixing the code won't fix this and as the value is most likely not a function you get this " not a function error" when you try to e.g. call a string or a number. And glad to see that you discovered the way to fix it -> just refresh the page that reloads the javaScript and thereby resets the built-in functions.


O.K. What about this code. It sill giving me an error:

var sleepCheck = function (numHours) {

if (numHours >= 8) {
return "You're getting plenty of sleep." + " " + "Maybe even too much.";}

else {
    return "Get some more shut eye!";



Thanks a lot guys!


If I write at the end:

Still doesn't work.


Seems to be ok copy the messages from the instruction probably a typo somewhere.


Thanks haxor789!

Here are the instructions:

  1. Write a function named sleepCheck that takes the parameter numHours

  2. Inside the function, write an if statement where if the number of hours of sleep is greater than or equal to 8, the computer will return "You're getting plenty of sleep! Maybe even too much!";.

  3. Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";

Then call the function with different hours of sleep

  1. Call the function with 10 hours of sleep, like this: sleepCheck(10);
  2. Call the function with 5 hours of sleep.
  3. Call the function with 8 hours of sleep.


Hi guys,

Yes, it was a typo. I put period after "You're getting plenty of sleep!" instead of exclamation mark.

Thanks everyone!