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?

Fill in the blanks please:

Procedure: named group of programming instructions that may have parameters and return values Parameters: input values Arguments: specify the values of parameters Modularity: modules! Procedural Abstraction: name pr a process that allows for an understanding of the procedure What are some other names for procedures?: pseudocode

Why are procedures effective?: can help simplify the code, and we know what to look for and code in the actual program

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

def BinaryConvert(number):
## recursive code 
    if number >= 1: 
        BinaryConvert(number // 2) ##based on the power of 2, it will shift the 0 or 1 right
    print(number % 2, end = '') ## the end function prevents it from printing a new line --> binary output is only one line.

    # Driver Code
number = 31
BinaryConvert(number)

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)

const nums = [1, 2, 3, 4, 5, ,6]
Math.min(nums)
Math.max(nums)
NaN

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 Player(name, position, average) {
    this.name = name;
    this.position = position;
    this.average = average;
    this.role = "";
}

Player.prototype.setRole = function(role) {
    this.role = role;
}

Player.prototype.toJSON = function() {
    const obj = {name: this.name, position: this.position, average: this.average, role: this.role};
    const json = JSON.stringify(obj);
    return json;
}

var manager = new Player("Bob Melvin", "Catcher", ".233");
LogItType(manager);
LogItType(manager.toJSON());

manager.setRole("Manager");
LogItType(manager);
LogItType(manager.toJSON());
evalmachine.<anonymous>:19
LogItType(manager);
^

ReferenceError: LogItType is not defined
    at evalmachine.<anonymous>:19:1
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.runInThisContext (vm.js:97:38)
    at run ([eval]:1020:15)
    at onRunRequest ([eval]:864:18)
    at onMessage ([eval]:828:13)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:758:12)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
var players = [
    new Player("Manny Machado", "Third Base", ".299"),
    new Player("Trent Grisham", "Center Field", ".185"),
    new Player("Jake Cronenworth", "Second Base", ".238"),
    new Player("Jurickson Profar", "Left Field", ".240"),
    new Player("Ha-Seong Kim", "Shortstop", ".252"),
    new Player("Brandon Drury", "First Base", ".226"),
    new Player("Jorge Alfaro", "Catcher", ".249"),
    new Player("Wil Myers", "Right Field, First Base", ".255"),
    new Player("Juan Soto", "Right Field", ".242"),
    new Player("Austin Nola", "Catcher", ".248"),
    new Player("Josh Bell", "Designated Hitter, First Base", ".191"),
    new Player("Jose Azocar", "Outfield", ".272"), 
];

function Padres(manager, players){

    manager.setRole("Manager");
    this.manager = manager;
    this.padres = [manager];
    
    this.players = players;
    this.players.forEach(player => { player.setRole("Player"); this.padres.push(player); });

    this.json = [];
    this.padres.forEach(player => this.json.push(player.toJSON()));
}

sd2022 = new Padres(manager, players);

LogItType(sd2022.padres);
LogItType(sd2022.padres[0].name);
LogItType(sd2022.json[0]);
LogItType(JSON.parse(sd2022.json[0]));
Padres.prototype._toHtml = function() {
    var style = (
        "display:inline-block;" +
        "border: 2px solid grey;" +
        "box-shadow: 0.8em 0.4em 0.4em grey;"
    );

    var body = "";
    body += "<tr>";
    body += "<th><mark>" + "Name" + "</mark></th>";
    body += "<th><mark>" + "Position" + "</mark></th>";
    body += "<th><mark>" + "Batting Average" + "</mark></th>";
    body += "<th><mark>" + "Role" + "</mark></th>";
    body += "</tr>";
    
    for (var row of sd2022.padres) {
        
        body += "<tr>";
        
        body += "<td>" + row.name + "</td>";
        body += "<td>" + row.position + "</td>";
        body += "<td>" + row.average + "</td>";
        body += "<td>" + row.role + "</td>";
        
        body += "<tr>";
      }
    
       
      return (
        "<div style='" + style + "'>" +
          "<table>" +
            body +
          "</table>" +
        "</div>"
      );
    
    };
    
    
    $$.html(sd2022._toHtml());