Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Noob Looking For A Little JS Help

    Hello CodingFoums,

    I am Effexion. I am brand new to this site, and joined in the hope that someone could help me out a little.

    I am using Codecademy to learn Javascript, but I have come across a problem quite early on. Following is the code with comments and the error.

    Any help will be greatly appreciated.

    // On line 2, declare a variable myName and give it your name.
    var myName = "Mikey";
    // 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.
    var myName = "Mi";
    // On line 9, use console.log to print out the myName variable.
    console.log (myName);


    ERROR: TypeError: Property 'log' of object #<Object> is not a function

    Really confused. I thought I was doing so well lol.

    ~Effexion

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,133
    Thanks
    38
    Thanked 504 Times in 498 Posts

    Question

    What browser are you using?
    Not all support the console.log

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    What browser are you using?
    Not all support the console.log

    I cleared cache and cookies and logged back in. That sorted it. Thanks for your reply man.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,563 Times in 4,527 Posts
    [quote]
    // On line 7, change the value of myName to be just the first 2
    // letters of your name.
    var myName = "Mi";
    [/code]
    That answer is wrong because you are REPEATING the use of the var keyword.

    It works, but it's incorrect. Each variable should be created *ONCE* using var and then just referred to by name thereafter.

    ***********

    I think it is likely, also, that you misunderstood the INTENT of that question. I think you were supposed to get the first two letters of the name NO MATTER WHAT THE NAME was. In other words, using a JavaScript function or method.

    *PROBABLY* the correct answer to that question is:
    Code:
    myName = myName.substring(0,2);
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    what happens if your name is Q, like that guy in the Bond movies?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,252
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by xelawho View Post
    what happens if your name is Q, like that guy in the Bond movies?
    No problem.

    Code:
    var myName = "Q";
    myName = myName.substring(0,2);
    alert (myName);  // Q
    But can a person's real name (as opposed to a screen name or nickname) consist of only one letter of the Roman alphabet?

    I am aware of former president Harry S Truman. And no, he did not a period after the "S" because it was an actual "name". But S was not his only or complete name.
    Last edited by Philip M; 05-06-2013 at 02:00 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •