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.
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Old Pedant View Post

    The "framework" that will test his code is not even going to LOOK at the return value from the function.
    Without seeing it's source code, how can you possibly know that?

    However unnecessary in the circumstances, the requirement was to use return, so it could be critical.

  2. #17
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Read my prior answer about needing a new brain.

    I flat out misread the original post.
    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.

  3. #18
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    You seem to have got your knickers in a twist. It was a simple enough question. Surely what the OP is looking for was (as xelawho has said)

    Code:
    <script type="text/javascript">
    
    var fullname = "";  // fullname declared outside the function is a global variable
    function Bold_Name(which) {
    fullname = "<b>";
    fullname += which;
    fullname += "</b>";
    return fullname;
    }
    
    alert (Bold_Name("Philip"));
    </script>

    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.

  4. #19
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,883
    Thanks
    56
    Thanked 539 Times in 536 Posts
    oh, my. I'm beginning to see another reason why we shouldn't be doing homework questions. From the instructions:

    Do not ... initialize fullname, it will be done for you.
    so this:
    Code:
    var fullname = "";
    will wipe out the value of the established variable. ie, FAIL

    there's nothing about Bold_Name accepting an argument, so this:
    Code:
    function Bold_Name(which)
    will also naturally FAIL

    the simplest answer I can see here is

    Code:
    function Bold_Name() {
    return "<b>"+fullname+"</b>";
    }
    slightly fancier being

    Code:
    function Bold_Name() {
    var str = "<b>";
    str += fullname;
    str += "</b>";
    return str;
    }


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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