if/else - spot the errors


Goal:

Write the following snippets on the whiteboard and ask students to fix the errors.

Steps:

  1. Have students take turns and tell them to only fix ONE mistake so everyone gets plenty of turns.
  2. Ask students not to erase the original code, just put a line through an error and write their suggestion above. That way if the fix is not correct, another student can still see the original.

    Snippet 1:
    int today = JOptionPain.ShowInputDialogue( What day is it? );
    
    if (today == "Saturday ) {
          System.print("Sleep in");
    elseif (today == Sunday) {
          System.out ("Sleep in");
    else
          JOptionPane.showMessageDialog("Get up and go to school!")
    }
    


    Snippet 2:
    int animal = JOptionPane.showMessageDialogue(null, "Which animal?" );
    
    if (animal == octopus ) {
          JOptionpane.showMessageDialog(nul, "legs: 8, eats: crabs" );
    if (animal == panda); 
          JOptionPane.showMassageDialog(null "legs: 4, eats: bamboo" )
    else {
          JoptionPane.showMessageDialog("animal not found");
    }