<file_sep># ACA-todo-list.js
<file_sep>'use strict';

$(document).ready(function() {
    // You code here
    $.ajax('https://reqres-api.herokuapp.com/api/users/', {
        success: function successHandler(response) {
            $('tbody').empty();
            response.forEach(function(user) {
                var $str = "<tr><td>" + user.id + "</td><td>" + user.first_name + "</td><td>" + user.last_name + "</td><td><a href='#' data-id='" + user.id + "'>View</a></td></tr>";
                $("tbody").append($str);
            });
            $('tbody tr td a').click(function(event) {
                event.preventDefault();
                var $id = $(this).data('id');
                var $url = "https://reqres-api.herokuapp.com/api/users/" + $id;
                $.ajax($url,{
                  success: function(person){
                    var $string = $("<h2>" + person.first_name + ' '+ person.last_name + "</h2><h4>" + person.occupation + "</h4><p>" + person.phone +"</p><p>" + person.address + "</p><img src='"+ person.avatar+ "'>");
                    $('#details').html($string);
                  }
                })
            });
        }
    });
});
<file_sep># ACA-towers-app.js
<file_sep>'use strict';
// lets the application know that the page is loaded and ready to execute the code
$(document).on('ready', function() {
// Put app logic in here
// how you get all of the divs with "data" in the element tag
//.click() - when you click these things (anything)
var $datacell = $('[data-cell]');
var playerTurn = "X";
var $button = $('#clear');


//html board layout:
//0 1 2
//3 4 5
//6 7 8

//how to loop thorugh winning combos this would need to go in the check for win function
// var winningcombo = [[0,1,2], [2,3,4]]
//
// for (var i =0; i < winningcombo.length, i++) {
// if(
//
// $('[data-cell="'+ winningcombo[i][0]'"]') === playerTurn &&
// $('[data-cell="'+ winningcombo[i][1]'"]') === playerTurn &&
// $('[data-cell="'+ winningcombo[i][2]'"]') === playerTurn){
// return true;
// }
// }

var datacells0 = $('[data-cell="0"]').text();
var datacells1 = $('[data-cell="1"]').text();
var datacells2 = $('[data-cell="2"]').text();
var datacells3 = $('[data-cell="3"]').text();
var datacells4 = $('[data-cell="4"]').text();
var datacells5 = $('[data-cell="5"]').text();
var datacells6 = $('[data-cell="6"]').text();
var datacells7 = $('[data-cell="7"]').text();
var datacells8 = $('[data-cell="8"]').text();

//Using jQuery, set a click listener on all of the [data-cell]s that SETs playerTurn as .text() on $(this) by $(this).text(playerTurn)

$datacell.click(function() {

$(this).text(playerTurn)

checkForWin();

playerTurn = (playerTurn === "X") ? "O" : "X";
});

//Add a button with an id="clear" that will not only clear the board, but reset the player to player 'X'
$button.click(function() {
$datacell.empty();
$("#announce-winner").empty();
playerTurn = "X";
});


//

function horizontalWin() {

if (datacells0 === playerTurn && datacells1 === playerTurn && datacells2 === playerTurn ||
datacells3 === playerTurn && datacells4 === playerTurn && datacells5 === playerTurn ||
datacells6 === playerTurn && datacells7 === playerTurn && datacells8 === playerTurn) {

return true;

}
}

function verticalWin() {
if (datacells0 === playerTurn && datacells3 === playerTurn && datacells6 === playerTurn ||
datacells1 === playerTurn && datacells4 === playerTurn && datacells7 === playerTurn ||
datacells2 === playerTurn && datacells5 === playerTurn && datacells8 === playerTurn) {

return true;
}
}

function diagonalWin() {
console.log('test2: ' + datacells8);
if (datacells0 === playerTurn && datacells4 === playerTurn && datacells8 === playerTurn ||
datacells2 === playerTurn && datacells4 === playerTurn && datacells6 === playerTurn) {

return true;
}

}

function checkForWin() {

datacells0 = $('[data-cell="0"]').text();
datacells1 = $('[data-cell="1"]').text();
datacells2 = $('[data-cell="2"]').text();
datacells3 = $('[data-cell="3"]').text();
datacells4 = $('[data-cell="4"]').text();
datacells5 = $('[data-cell="5"]').text();
datacells6 = $('[data-cell="6"]').text();
datacells7 = $('[data-cell="7"]').text();
datacells8 = $('[data-cell="8"]').text();

if (horizontalWin() || verticalWin() || diagonalWin()) {

//need to select '#announce-winner' and SET its .text() to say 'Player ' + playerTurn + 'Wins!'

$('#announce-winner').text('Player ' + playerTurn + ' Wins!');

return true;
// process.exit();
}

}

});
<file_sep>'use strict';

$(document).ready(function() {
        $.ajax("http://127.0.0.1:8080/apps/11gist-blog/api/gists.json", {
                success: function(gists) {
                    console.log(gists);
                    gists.forEach(function(post) {
                        if (post.description.startsWith('#post')) {
                            var strPostDiscription = post.description.slice(5);
                            var $post = $(`<a href="#" data-url="${post.url}"
                data-comments="${post.comments_url}" >${strPostDiscription}</a>`);
                            $("ul#posts").append($post);
                        }
                        $('ul#posts a').click(function(event) {
                            var $that = $(this).data('url').id;
                            console.log($that);
                            event.preventDefault();
                            $('ul#posts a').removeClass('active');
                            $(this).addClass('active');
                            $.ajax($(this).data('url'), {
                                success: function(post) {
                                    var postContent = post.files['post.md'].content;
                                    $('div#post').html(marked(postContent));
                                    $('div#post p').attr('style', 'text-align: left');
                                }
                            });
                            $.ajax($(this).data('comments'), {
                                success: function(comments) {
                                    $('ul#comments').empty();
                                    comments.forEach(function(comment) {
                                        var $comment = $('<blockquote><li><span class="comment-user">' + comment.user.login + '</span> says "<span class="comment-body">' + comment.body + '"</span></li></blockquote>');
                                        $('#comments').append($comment);
                                    })
                                }
                            })

                        });
                    });
                });
        });
}
//     // Your code here
// So let's run through the API real quick. First, in your terminal, navigate to to your app directory:
// After starting up a server in the app directory, navigate in your browser to http://127.0.0.1:8080/apps/11gist-blog/api/gists.json, here you will see the top level of the api, with all of the gists. In each gist, you will see a "url" key. Navigate to that URL. In that address you will see another JSON object. Look for a "files" key with an object containing a file. In that file you'll see the "content" of the file. Next look for a "comments_url". At that address, you'll see a collection of comments, with keys such as "user" and "body".
// Spec 1.1
// Using jQuery to make an AJAX call, insert a list of links into #posts using JavaScript forEach with the "description" of each gist as the text.
// Spec 1.2
// Within each loop, write an if condition to insert only gists that start with a '#post' in the "description". After fitering, remove the '#post ' from the title.Spec 1.3
// Set the href attribute on each link to "#", and a "data-url" attribute equal to the "url" value.
// Spec 2
// After the links are are inserted, add a click listener, and prevent the default event from occuring. Then make an ajax call with the "data-url" value, grabbing it with $.data('url').
// Spec 3
// Insert the "content" of the file named post.md into #post.
// Spec 3.1
// Since our "content" is written in Markdown, we can use the Marked.js library to convert the content to html. Simply call marked() on your content. e.g. marked(content).
// Spec 4
// After inserting your content, make another ajax call using the "comments_url", and insert the ["user"]["login"] and "body" in a list in #comments.
// Spec 5
// Make it look nice! This is going to be YOUR blog! Take a look at some CSS frameworks, such as:
// Materialize - Framework based on Google's Material Design Guidelines
// Material Design Lite - Google's Official CSS Material Framework
// Bootstrap - Probably the most popular CSS framework on the web. Made by Twitter
// Foundation - Industry standard of CSS Frameworks
// Skeleton - Beautifully simple CSS Framework
// Spec 7
// After development and styling on your blog dies down, you can plug it into your Github account. If done correctly, you should only have to change one url: http://127.0.0.1:8080/apps/11gist-blog/api/gists.json to https://api.github.com/users/<your github username>/gists. Now whenever you create a gist with "#post" in the title and a file named post.md, it will automatically be pulled into your blog!
<file_sep>'use strict';

var assert = require('assert');

// ****
// Functions
// ****

// Problem 0:
// alwaysFalse() is a function that always
// returns the boolean value false

function alwaysFalse() {
    return false;
}

// You can also define functions this way,
// by assigning function definitions to variable
var alwaysTrue = function() {
    return true;
};

// Problem 1:
// equals(argument1, argument2) is an empty function
// return a boolean expression that is true when
// argument1 is equal to argument2
var argument1 = 5;
var argument2 = 4;

function equals(argument1, argument2) {
    if (argument1 === argument2) {
        return true;
    } else {
        return false;
    }
}

// Problem 2:
// lessThanOrEqualTo(parameter1, parameter2) is an empty function
// return a boolean expression that is true when
// parameter1 is less than or equal to parameter2
var parameter1 = 1;
var parameter2 = 2;

function lessThanOrEqualTo(parameter1, parameter2) {
    if (parameter1 <= parameter2) {
        return true;
    } else {
        return false;
    }
}

// Problem 3:
// write a function named add(number1, number2)
// add will add two numbers and return the result
var number1 = 1;
var number2 = 2;

function add(number1, number2) {
    return number1 + number2;
}
var number3 = add(2, 4);
console.log(number3);


// Problem 4:
// write a function named addThree(number1, number2, number3)
// this function will add three numbers
// you must call your function add() in addThree()
function add(number1, number2) {

    return number1 + number2;
}

function addThree(number1, number2, number3) {

    return number1 + number2 + number3;

}

var addFive = add(1, 2) + addThree(3, 4, 5);

addFive;

// ****
// Concept Checkpoint
//
// Write your answer in comments
//
// What is a function? How do you define a function in Javascript?
//
// Your Answer Goes Here:
//In Javascript a function is a set of statements that performs a task or calculates a value.
// Functions are first-class objects. Like other objects, functions can have properties and methods.
// Functions can be called(invoked). This distinguishes them from other objects.
//		  //
// To define a function in Javascript we need the following:
// 1. The keyword function
// 2. The name of the function
// 3. A list of arguments for the function, seperated by commas and enclosed in parantheses.
// 4. The statement or statements (code to be executed) enclosed with curly brackets.
//		  //
//
// What is a return value?
//
// Your Answer Goes Here:
//The return statement stops the execution of a function and returns a value from that function. While updating global variables is one way to pass information back to the code that called the function , this is not an ideal way of doing so.
//
// How do you define a named function?
//
// Your Answer Goes Here:
//Named functions can be either declared in a statement or used in an expression. Named function expressions create readable stack traces. The name of the function is bound inside its body, and that can be useful. And we can use the name to have a function invoke itself, or to access its properties like any other object.
//
// What is a parameter? What is an argument? Is there a difference between the two?
// Your Answer Goes Here:
//// parameter-The Arguments Object. JavaScript functions have a built-in object called the arguments object. The argument object contains an array of the arguments used when the function was called (invoked).

// argument- The Arguments Object. JavaScript functions have a built-in object called the arguments object. The argument object contains an array of the arguments used when the function was called (invoked).
// A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function.
// ****


// ****
// Modulo % Operator
// ****

// Problem 5:
// isEven(number) is a function that
// returns true if number is even (divisible by 2),
// else returns false
// complete isEven() by returning a boolean expression
var number = 8

function isEven(number) {
    if (number % 2 === 0) {
        return true;
    } else {
        return false;
    }
}

// Problem 6:
// isDivisibleByThree(number) is a function that
// returns true if number is divisible by 3,
// else returns false
// complete isDivisibleByThree() by returning a boolean expression
var number = 9;

function isDivisibleByThree(number) {
    if (number % 3 === 0) {
        return true;
    } else {
        return false;
    }
}


// ****
// Conditionals
// ****


// Problem 7:
// whichSpecies(character) is a function that
// should return "dog" when character is 'scooby'
// should return "cat" when character is 'garfield'
// should return "fish" when character is 'nemo'
// should return false if character is anything else

var character = 'scooby';
function whichSpecies(character) {
        if (character === 'scooby') {
            return ('dog');
        } else if (character === 'garfield') {
            return ('cat');
        } else if (character === 'nemo') {
            return ('fish');
        } else {
            return false;
        }
    }


// Problem 8:
// write a function named testNumber(number) with the following requirements.
// The function should:
// return the string "divisible by 4" when number % 4 === 0
// return the string "divisible by 2" when number % 2 === 0
// return the string "divisible by 3" when number % 3 === 0
// return the string "divisible by 5" when number % 5 === 0
var number = 8;
 function testNumber(number){
   if (number % 4 === 0){
         return ('divisible by 4');
     }
     else if (number % 2 === 0){
         return ('divisible by 2');
     }
     else if (number % 3 === 0){
         return ('divisible by 3');
     }
     else if (number % 5 === 0){
         return ('divisible by 5');
     }
 }

// ****
// Concept Checkpoint
//
// Write your answer in comments
//
// In your own words, explain what conditionals do.
//
// Your Answer Goes Here:
//
//
// ****

// ****
// Tests
// ****

describe('Lesson 2 Homework', function() {

    describe('Functions', function() {
        describe('Problem 0: alwaysFalse()', function() {
            it('should return false', function() {
                assert.equal(alwaysFalse(), false);
            });
        });

        describe('Problem 0: alwaysTrue()', function() {
            it('should return true', function() {
                assert.equal(alwaysTrue(), true);
            });
        });

        describe('Problem 1: equals()', function() {
            it('should return true when argument 1 equals argument 2, else return false', function() {
                assert.equal(equals(3, 3), true);
                assert.equal(equals(3, null), false);
                assert.equal(equals('bob', ''), false);
                assert.equal(equals('bob', 'bob'), true);
            });
        });

        describe('Problem 2: lessThanOrEqualTo()', function() {
            it('should return true when parameter 1 is less than or equal to parameter 2, else return false', function() {
                assert.equal(lessThanOrEqualTo(3, 3), true);
                assert.equal(lessThanOrEqualTo(3, 4), true);
                assert.equal(lessThanOrEqualTo(4, 1), false);
            });
        });

        describe('Problem 3: add(number1, number2)', function() {
            it('should be defined and of type function', function() {
                assert(!(typeof add === 'undefined'));
                assert(typeof add === 'function');
            });

            it('should add two numbers and return the result', function() {
                assert.equal(add(3, 3), 6);
                assert.equal(add(3, 7), 10);
            });
        });

        describe('Problem 4: addThree(number1, number2, number3)', function() {
            it('should be defined and of type function', function() {
                assert(!(typeof addThree === 'undefined'));
                assert(typeof addThree === 'function');
            });

            it('should add three numbers and return the result', function() {
                assert.equal(addThree(3, 3, 3), 9);
            });
        });
    });

    describe('Modulo % operator', function() {
        describe('Problem 5: isEven(number)', function() {
            it('should return true if number is even, else false', function() {
                assert.equal(isEven(4), true);
                assert.equal(isEven(3), false);
            });
        });

        describe('Problem 6: isDivisibleByThree(number)', function() {
            it('should return true if number is divisible by 3, else false', function() {
                assert.equal(isDivisibleByThree(3), true);
                assert.equal(isDivisibleByThree(4), false);
            });
        });
    });

    describe('Conditionals', function() {
        describe('Problem 7: whichSpecies(character)', function() {
            it('should return "dog" when character is scooby', function() {
                assert.equal(whichSpecies('scooby'), 'dog');
            });
            it('should return "cat" when character is garfield', function() {
                assert.equal(whichSpecies('garfield'), 'cat');
            });
            it('should return "fish" when character is nemo', function() {
                assert.equal(whichSpecies('nemo'), 'fish');
            });
            it('should return false if character is anything else', function() {
                assert.equal(whichSpecies('stitch'), false);
            });
        });

        describe('Problem 8: testNumber(number)', function() {
            it('should be defined and of type function', function() {
                assert(!(typeof testNumber === 'undefined'));
                assert(typeof testNumber === 'function');
            });

            it('should return "divisible by 4" when number is divisible by 4', function() {
                assert.equal(testNumber(4), 'divisible by 4');
            });
            it('should return "divisible by 2" when number is divisible by 2', function() {
                assert.equal(testNumber(2), 'divisible by 2');
            });
            it('should return "divisible by 3" when number is divisible by 3', function() {
                assert.equal(testNumber(3), 'divisible by 3');
            });
            it('should return "divisible by 5" when number is divisible by 5', function() {
                assert.equal(testNumber(5), 'divisible by 5');
            });
        });
    });

});
