Grade: I got a 1/1

MY OWN NOTES:

  • When developing procedures, you should ask yourself some questions like
    • What am I going to name my procedure? (It should reflect the purpose of the code)
    • What parameters do I need?
    • What data would I need to take in to accomplish my goal?
    • Do I want my procedure to give a numerical value, or complete an action?
  • Procedures are SUPER effective and save a lot of time because they are much easier to debug

Take some additional notes that you would like here for 3.12 and 3.13. We will be looking for additional notes from the presentation.

What are procedures?

VOCAB:

Procedure: named group of programming instructions that may have parameters and return values.

Parameters: input values of a procedure

Arguments: specify the values of the parameters when a procedure is called

Modularity: Separating a program's functions into independent pieces or blocks, each containing all the parts needed to execute a single aspect of the functionality

Procedural Abstraction: process that allows a procedure to be used only knowing WHAT it does, not HOW it does it

What are some other names for procedures?: other names for procedures include methods, strategies,

Why are procedures effective?: have the ability to alter the result without actually changing the calls to the program, Convenient to change the actions if there is an error in the code, MUCH better than reviewing code WITHOUT a procedure, able to break the code up and abstract what different part of the code does, helps identify errors/bugs

Challenge 1 below: Add the command that will call the procedure.

function convertToBinary(n) {
    const result = n.toString(parseInt(2));
    return result;
}
convertToBinary(10);
'1010'

Challenge 2 below: Complete the Min and Max procedure in either JavaScript and Python using the instructions from the JavaScript page. (JavaScript will get you a extra 0.1)

function findMax(numberA, numberB) {
    if (numberA > numberB) {
        return numberA;
    }
    else {
        return numberB;
    }
}

function findMin(numberA, numberB) {
    if (numberA < numberB) {
        return numberA;
    }
    else {
        return numberB;
    }
}

console.log(findMax(10, 20));
console.log(findMin(10, 20));
20
10

Homework/Hacks: For the hw, you have two options, easy or hard. The easy hack is for a 2.7 + extra work for the full 3. The easy hack is simply creating your own procedure with your own creativity. Since there is a lot of leeway for this one, you must do additional work to get a 3. For the hard hack, below is the start to a character to binary convertor. This is just a template, but the goal is to translate "APCSP" into binary. You can delete the existing code if you want. The only contraint is that you must use a procedure. Doing this will get you a 3.

function convert(hello){
    var output = "";


    output.innerHTML = "";
    for (var i = 0; i < hello.length; i++){
      output = output + hello[i].charCodeAt(0).toString(2) + " ";
    }
    return output;
  }


console.log("APCSP to binary is...")
console.log(convert("APCSP"));
APCSP to binary is...
1000001 1010000 1000011 1010011 1010000 

I did everything in JavaScript, and I also did the challenge for the HW (converting "APCSP" to binary).