Thursday, 10 September 2026

Code Solutions

/* This program should clean up all the balls in any size world. */
function main() {
    while (leftIsClear()) {
        cleanRow();
        comeBack();
        moveUp();
    }
    cleanRow();
    comeBack();
    
    if (leftIsBlocked()) {
        returnHome();
    }
}

/* Karel moves up to the next row.
 * Precondition: Karel is at the start of a just cleaned row.
 * Postcondition: Karel is at the start of the next row to
 * be cleaned, facing east. */
function moveUp() {
    turnLeft();
    move();
    turnRight();
}


/* This brings Karel back to the starting position on the row.
 * Precondition: Karel is at the end of the row, facing a wall.
 * Postcondition: Karel is at the start of the same row, facing
 * east.
 */
function comeBack() {
    turnAround();
    while (frontIsClear()) {
        move();
    }
    turnAround();
}

/* This cleans one row of Karel's world.
 * Precondition: Karel is in the first column, facing east
 * Postcondition: Karel is at the end of the row, facing
 * east, and all balls in the row have been picked up.
 */
function cleanRow() {
    while (frontIsClear()) {
        cleanSpot();
        move();
    }
    cleanSpot();
}

/* This picks up a tennis ball, but only if it is there. */
function cleanSpot() {
    if (ballsPresent()) {
        takeBall();
    }
}

/* This brings Karel back to the starting position, facing east.
 * Precondition: Karel is at the end of the clean up.
 * Postcondition: Karel is back to (1,1), facing east.
 */
function returnHome(){
    turnRight();
    while (frontIsClear()) {
        move();
    }
    turnLeft();
}

main();

Wednesday, 9 September 2026

Welcome to Programming 11/12/AP

Lab Expectations:
  • No food or drinks in the computer lab!!!! 
  • Attend all classes. If you are absent, it is your responsibility to make up the work (not mine). 
  • Complete all of the assignments to the best of your ability. You will not succeed in this class if you don’t do the work. 
  • Be prepared in your seat, when the second bell goes 
  • Only one person talks at a time. This includes any/all announcements. Do not be typing on the keyboard or playing with your mouse also falls under this category. 
  • Leave your area as you found it. Push in your chair, log out of the computer , the equipment should be in the condition you found it. 
  • CLOSE THE CLASSROOM DOOR!!!
  • Do not live on your cellular phone, if I notice it, I will take it away.  

Programming 11 - Coding

Programming JavaScript at CodeHS.com  Go to Link  
Class code is DF5BB

Programming using Python at CodeHS.com  Go to Link 
Class code is 26744

If you're new and need not sure of your capabilities start with:
Programming using Karel at CodeHS.com  Go to Link
Class code is 3549F

Once you've finished that, you can go onto any of the ones listed below.