where is my error

Discussion in 'JavaScript' started by paffdevel, Feb 20, 2016.

  1. #1
    Hello friend,
    Please visit the code and find my error.
    Thanks

    <script>
    $(function() {
    var hide;
    $('input[name="o1"]').on('click', function () {
    var that = this;
    hide = $(this).val() === 'sell' ? '.buy' ? '.transport' : '.transport' : '.sell' ;
    $(hide).fadeOut('slow', function () {
    $('.' + $(that).val()).fadeIn('slow');
    });
    });
    });
    </script>
    Code (markup):

     
    Last edited by a moderator: Mar 10, 2016
    paffdevel, Feb 20, 2016 IP
  2. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #2
    What is the purpose of this ternary: hide = $(this).val() === 'sell' ? '.buy' ? '.transport' : '.transport' : '.sell';

    Are you trying:
    if ( $(this).val() === 'sell' || $(this).val() === '.buy' || $(this).val() === '.transport' || $(this).val() === '.transport' || $(this).val() === '.sell' ) { hide = $(this).val(); }

    Also: var hide; declaration should be in the callback function of "on", but this is not the problem.
     
    Blizzardofozz, Mar 10, 2016 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #3
    don't be afraid of white space. Break those big one line checks into several lines to help with debugging.

    Here's how I'd get started https://jsfiddle.net/qv1uva49/

    but in actual fact your error is really simple - in that long comparison you are adding the "." to the class name and then in your fade out you are adding it again.
     
    sarahk, Mar 10, 2016 IP