3

I have tried numerous ways...what am I doing wrong??? I am determined to learn and really understand this.

//On line 2, declare a variable myName and give it your name.
var myName = "Jeanne";
//On line 4, use console.log to print out the myName variable.
console.log ("Jeanne");
//On line 7, change the value of myName to be just the first 2 letters of your name.
myName.substring(0, 2);
//On line 9, use console.log to print out the myName variable;
console.log("Jeanne");
tooheymomster
  • 101
  • 2
  • 14
  • the error that I keep getting is: TypeError: console.log is not a function, which is partly why I am confused. – tooheymomster Dec 28 '12 at 07:40
  • If using IE: http://stackoverflow.com/questions/690251/what-happened-to-console-log-in-ie8 , http://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function/5473193#5473193 (Search as appropriate if you are using a different browser/environment.) –  Dec 28 '12 at 07:41

10 Answers10

2

Make sure that you are using a browser that supports console.log(Firefox with Firebug, Google Chrome) if you are having problems with your browser, try to run your code in jsfiddle

EDIT

I have tried to run your code in jsfiddle, and in my browser(Chrome and IE9), they both work perfectly.

Based from the comment that I have read you're using firefox. if that's the case make sure you have the firebug plugin installed. you can get it here

KyelJmD
  • 4,512
  • 9
  • 49
  • 72
1

You need to assign to the result of substring back to variable to get the substring result. Use that varible to print the substring result.

Live Demo

myName = myName.substring(0, 2);
console.log(myName );
Adil
  • 139,325
  • 23
  • 196
  • 197
1

Probably your error is that you getting "Jeanne" on screen every time.

It is because you are printing constant, and not your variable. Try use this for printing:

myName = myName.substring(0, 2);
console.log (myName);

And as stated in the other answers - make sure you are using a browser that supports console.log

JleruOHeP
  • 8,924
  • 2
  • 36
  • 65
  • @tooheymomster Well, that would be so easily addressed *if including such information in the post*. I suspect it is because an older version of IE is being used .. –  Dec 28 '12 at 07:40
1

You are doing it all correct just log the processed variable instead of raw name,Done !

//On line 2, declare a variable myName and give it your name.
var myName = "Jeanne";
//On line 4, use console.log to print out the myName variable.
console.log (myName );
//On line 7, change the value of myName to be just the first 2 letters of your name.
myName=myName.substring(0, 2);
//On line 9, use console.log to print out the myName variable;
console.log(myName );
sajanyamaha
  • 2,958
  • 2
  • 22
  • 39
1

Among other things, make sure you're using a browser that supports "console.log". This means Chrome, or FireFox with the Firebug plugin installed, or Internet Explorer with the developer tools open. And then of course open the developer tools. For Chrome, it's ctrl-shift-I; for everything else it's F12.

Ken Smith
  • 19,697
  • 13
  • 93
  • 139
1

Inorder for the console.log to print out your var value, you should include the variable in between paraenthesis of the console.log

this is shown in the below example;

//On line 2, declare a variable myName and give it your name. var myName = "Jeanne";

//On line 4, use console.log to print out the myName variable. console.log (myName);

0

Strings in immutable so you should assign the results to a new variable.

0

Thank you everyone for your help! I really appreciate you being available and knowledgeable to answer questions. I did figure it out. Apparently the problem was with the substring. I had typed out the word substring in full. I guess it didn't like that and only needed the abbreviated substr.

//On line 2, declare a variable myName and give it your name.
var myName = "Jeanne";
//On line 4, use console.log to print out the myName variable.
console.log (myName);
//On line 7, change the value of myName to be just the first 2 
//letters of your name.
myName = myName.substr(0,2);
//On line 9, use console.log to print out the myName variable;
console.log (myName);
tooheymomster
  • 101
  • 2
  • 14
0

I had the console.log is not a function error, and spent a frustrating 15 minutes debugging it. It turned out I had a local variable called console! using window.console.log("...") did the trick.

Blisco
  • 542
  • 4
  • 13
0

Presumably you assigned something else to console.log, something that wasn't a function console.log = 5 console.log()

// obviously not referring to a function any more restart your environment. ie. refresh the page

HimalayanCoder
  • 8,577
  • 4
  • 49
  • 57