The o shortcut!


#1

I can't seem to figure out what's wrong with my code.. :frowning:

This is my code so far;

var main = function() {
$C'.article')click(function() {
$('.article').removeClass('current');
$('description').hide();

$(this).addClass('current');
$(this).children('.description').show();
});

$(document).keypress(function(event) {
if(event.which === 111) {
$('.current').children('.description').toggle();
}
};

$(document).ready(main);

Can anybody find my mistake?


#2

@frederikkepape,

the structure of our main-function looks like:

var main = function() {
     //BEGIN of main function-body 
    //
    //The CLICK event-handler is

    $('.article').click(function() {

     });

     //now comes the KEYPRESS event-handler

     $(document).keypress(function(event) {

       });
   //END of main function-body
   };

  $(document).ready(main);

#3

@frederikkepape @leonhard.wettengmx.n Is correct, you need to work on the structure of your main function. But, also take a look specifically at this line:

There's two problems in it. Can you spot them?

Hint

// ↓ this is a capital letter "C", but it needs to be a parentheses: "("
  $C'.article')click(function() {
            // ↑ you're missing a dot (.) here


#4

Thank you so much! It was the "C" !! I had gone completely blind on this one :slightly_smiling:


#5

3 posts were split to a new topic: Need help on "The O Shortcut"


#6

var main = function() {
$('.article').click(function(){
$('.article').removeClass('current');
$('.description').hide();
$(this).addClass('current');
$(this).children('.description').show();
});
$(document).keypress(function(event){
if(event.which===111){
$('.current').children('.description').toggle();
});
};
$(document).ready(main);
What is wrong ? I can't find anything


#7

@arrayblaster76099,
What Oops or Error message do you get.....


#8

Oops, try again. It looks like the o key isn't opening a description. Remember to toggle the current article's description inside the event handler. Look back at the instructions for the code.


#9

@arrayblaster76099,
In your document =keypress= Eventhandler
you are forgetting a closing-curly-bracket-}
to close the IF-code-block.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

The IF ELSE-IF-statement must be read as:
The IF-verb,
its condition in parenthesis ( )
and a code-block encapsulated in opening & closing curly-brackets-{ }

if ( condition1 ) {
// this code which will be executed IF CONDITION1 is TRUE
}

Now if condition1 rendered to false the if { code-block} is NOT executed
and if the JavaScript-parser finds an ELSE-IF-statement
it will start to evaluate that statement,
with it's condition2
and if this condition2 renders to true,
the { code-block } will be executed.

if ( condition1 ) {
     // this code which will be executed IF CONDITION1 is TRUE
}
else if ( condition2 ) {
        // condition1 ran into a -false-
        // this code which will be executed IF CONDITION2 is TRUE
}

Now encapsulated within the keypress Event-handler
as its function-body

$(document).keypress( function(event) {
    if ( condition1 ) {
        // this code which will be executed IF CONDITION1 is TRUE
    }
    else if ( condition2 ) {
       // condition1 ran into a -false-
       // this code which will be executed IF CONDITION2 is TRUE
    }
  });