Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a7a05c8
finished tests; working on implementing functions
MiHHuynh Aug 1, 2017
f461d1a
finished cceptNumbersOnly function
MiHHuynh Aug 1, 2017
2068677
finished mergeArrays function
MiHHuynh Aug 1, 2017
1828583
finished mergeObjects function. all tests passed
MiHHuynh Aug 1, 2017
a458e2d
finished productofarray, collectstrings, contains
MiHHuynh Aug 2, 2017
39ef109
finished search in recursion exercises
MiHHuynh Aug 2, 2017
24b3ca6
fixed typo in recursion tests
MiHHuynh Aug 2, 2017
f621f0a
edited sort function to compare numbers properly
MiHHuynh Aug 2, 2017
f42f98e
working on binary search
MiHHuynh Aug 2, 2017
a772b65
lodash exercises: drop, fromPairs
MiHHuynh Aug 2, 2017
ca2195c
head, take, takeRight, union, zipObject
MiHHuynh Aug 2, 2017
0d0e826
includes, sample, cloneDeep
MiHHuynh Aug 3, 2017
ef62251
some more functions for lodash exercise
MiHHuynh Aug 3, 2017
2beb2c8
added pickBy, omitBy
MiHHuynh Aug 3, 2017
fc8cca5
lodash functions, working on flatten
MiHHuynh Aug 3, 2017
e8ea7cd
initial commit for new pull request
MiHHuynh Aug 3, 2017
f986863
finished canvas shapes game
MiHHuynh Aug 3, 2017
608e512
removed repeated code
MiHHuynh Aug 3, 2017
1c272a4
removed some unnecessary elses
MiHHuynh Aug 3, 2017
8198184
removed if statement in expand
MiHHuynh Aug 3, 2017
d0f6d3e
implemented replaceWith using a map instead of forEach
MiHHuynh Aug 3, 2017
203b72d
reindented everything with spaces instead of tabs
MiHHuynh Aug 4, 2017
7dc77a3
finished ES2015 exercises
MiHHuynh Aug 4, 2017
4cdb916
padEnd, flatten
MiHHuynh Aug 5, 2017
069f8f6
flatten and flattenDeep
MiHHuynh Aug 5, 2017
c1c102d
zip
MiHHuynh Aug 5, 2017
97f33d1
flattenDeep, unzip
MiHHuynh Aug 6, 2017
d3084ba
finished hacker news clone
MiHHuynh Aug 8, 2017
19b05ab
finished lodash exercises and recursion stringifyNumbers
MiHHuynh Aug 8, 2017
c39642a
finished call apply bind exercises - ready for review
MiHHuynh Aug 10, 2017
3284548
finished parts 1 and 2 for prototypes exercises - ready for review
MiHHuynh Aug 10, 2017
a4e9826
incomplete hack or snooze. Need to work on implementing signup/login …
MiHHuynh Aug 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
66 changes: 66 additions & 0 deletions ajax_with_jquery_exercise/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hacker News Clone</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="panel panel-default custom-panel">
<div class="panel-heading custom-panel">
<span class="title">Hack or Snooze</span>
<span class="submit">submit</span> | <span class="favorites">favorites</span>
<span class="login">log in / sign up</span>
</div>
</div>
<div class="row login-signup-form">
<div class="col-md-3 col-md-offset-6">
<form action="submit" class="custom-form login-form">
<div class="form-group">
<label for="email">email:</label>
<input type="text" class="form-control" id="login-email">
</div>
<div class="form-group">
<label for="login-pw">password:</label>
<input type="password" class="form-control" id="url">
</div>
<button class="btn btn-default login-button">log in</button>
</form>
</div>
<div class="col-md-3 col-md-offset-3">
<form action="#" class="custom-form signup-form" id="signup-form">
<div class="form-group">
<label for="email">email:</label>
<input type="text" class="form-control" id="signup-email">
</div>
<div class="form-group">
<label for="pw">password:</label>
<input type="password" class="form-control" id="signup-pw">
</div>
<button type="submit" class="btn btn-default signup-button">sign up</button>
</form>
</div>
</div>

<!-- <form action="submit" class="custom-form submit-form">
<div class="form-group">
<label for="title">title:</label>
<input type="text" class="form-control" id="title">
</div>
<div class="form-group">
<label for="url">url:</label>
<input type="url" class="form-control" id="url" value="https://">
</div>
<button class="btn btn-default submit-button">submit</button>
</form> -->
<ol class="link-items">
</ol>

</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="script.js"></script>
</body>
</html>
135 changes: 135 additions & 0 deletions ajax_with_jquery_exercise/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
$(document).ready(function(){
var star = "<span class=\"glyphicon glyphicon-star-empty\" aria-hidden=\"true\"></span>";
var $linkItemsOl = $(".link-items");

$.ajax({
method: "GET",
url: "https://hacker-news.firebaseio.com/v0/topstories.json?"
}).then(function(topItems){
var top20 = topItems.slice(0,20);
for (let i = 0; i < top20.length; i++) {
$.ajax({
method: "GET",
dataType: "json",
url: `https://hacker-news.firebaseio.com/v0/item/${top20[i]}.json?print=pretty`
}).then(function(item){
addItemToList(item.title, item.url);
console.log(item.title + '\n' + item.url);
//item.title
//item.url
});

}
});

function addItemToList(itemTitle, itemUrl) {
var $newItem = $("<li>", { "class" : "item"});
var aTag = ` <a href="${itemUrl}">${itemTitle}</a>`;
$newItem.html(star + " " + aTag);
$linkItemsOl.append($newItem);
console.log(aTag);
}

$(".login").on("click", function(e) {
$(".login-form").toggle();
$(".signup-form").toggle();
});

$("login-signup-form").on("click", "login-button", function(e){
e.preventDefault();
var email = $("#login-email").val();
var pw = $("#login-pw").val();
$.ajax({
method: "POST",
url: "https://hn-favorites.herokuapp.com/login",
//Content-Type: "application/json"
data: {
"email" : email,
"password": pw
}
}).then(function(authKey){
console.log(authKey);
});
});

$("#signup-form").on("submit", function(e){
e.preventDefault();
var email = $("#signup-email").val();
var pw = $("#signup-pw").val();
console.log(email + pw);
$.ajax({
method: "POST",
url: "https://hn-favorites.herokuapp.com/signup",
data: {
"email" : email,
"password": pw
}
}).then(function(authKey){
console.log(authKey);
});
});

// what to do with the authkey?
// you need it to:
// GET all favorites
// DELETE a favorite

// when you click the log in button
// post to log in
//


// var $submitLink = $(".submit");
// var $submitForm = $(".submit-form");
// var $submitBtn = $(".submit-button");
// var $linkItemsOl = $(".link-items");
// var star = "<span class=\"glyphicon glyphicon-star-empty\" aria-hidden=\"true\"></span>";
// var $title = $("#title");
// var $url = $("#url");
// var $favSpan = $(".favorites");

// $submitLink.on("click", function(){
// $submitForm.toggle();
// });

// $("body").on("click", ".glyphicon", function(e){
// $(e.target).toggleClass("glyphicon-star-empty glyphicon-star");
// });

// $submitBtn.on("click", function(e){
// e.preventDefault();
// var title = $("#title").val();
// var url = $("#url").val();
// var $newItem = $("<li>");
// var aTag = ` <a href="${url}">${title}</a>`;
// $newItem.html(star + " " + aTag);
// $linkItemsOl.append($newItem);
// console.log(aTag);
// $title.val("");
// $url.val("https://");
// });

// $favSpan.on("click", function(e){
// var stars = $(".glyphicon");
// if ($favSpan.hasClass("favorites")) {
// for (let i = 0; i < stars.length; i++) {
// console.log(stars[i]);
// if ($(stars[i]).hasClass("glyphicon-star-empty")) {
// $(stars[i]).parent().hide();
// }
// }
// $favSpan.text("all");
// }
// else if ($favSpan.hasClass("all")) {
// for (let i = 0; i < stars.length; i++) {
// console.log(stars[i]);
// if ($(stars[i]).hasClass("glyphicon-star-empty")) {
// $(stars[i]).parent().show();
// }
// }
// $favSpan.text("favorites");
// }
// $favSpan.toggleClass("favorites all");
// });

});
58 changes: 58 additions & 0 deletions ajax_with_jquery_exercise/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.item {
margin-bottom: 10px;
}

.title, .submit, .favorites {
height: 3em;
margin: 5px;
}

.submit:hover, .favorites:hover, .all:hover, .login:hover, .signup:hover {
text-decoration: underline;
cursor: pointer;
}

.login {
margin-left: 63%;
}

.glyphicon:hover {
cursor: pointer;
}

.title {
font-size: 1.5em;
font-weight: bold;
}

.wrapper {
background-color: #f6f6ef;
width: 80%;
margin-top: 1em;
margin-left: auto;
margin-right: auto;
color: #828282;
}


.panel > .panel-heading, .custom-panel {
background-image: none;
background-color: rgb(255, 102, 0);
color: black;
border: 1px solid rgb(255, 102, 0);
}

/*.custom-form {
width: 15%;
margin-left: 68em;
margin-bottom: 2em;
display: none;
}*/

a, a:hover {
color: black;
}

.link-items {
margin-bottom: 50px;
}
55 changes: 55 additions & 0 deletions call_apply_bind_exercise/callApplyBind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function sumEvenArguments() {
var arr = [].slice.call(arguments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if you had learned spread yet, but you can do

function sumEvenArguments(...arr) {

var sum = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
sum += arr[i];
}
}
return sum;
}

function arrayFrom(arrLikeObj) {
var arr = [].slice.call(arrLikeObj);
return arr;
}

function invokeMax(fn, maxTimes) {
var counter = 0;
return function() {
if (counter >= maxTimes) {
return "Maxed Out!";
} else {
counter++;
return fn.apply(this, arguments);
}
}
}

function guessingGame(num) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job here.

var answer = Math.floor(Math.random()*10);
var guesses = 0;
return function(guess) {
if (guesses === num) {
return `No more guesses. The answer was ${answer}.`;
}
else {
guess++;
if (guess === answer) {
return "You got it!";
}
else if (guess > answer) {
return "You're too high!";
}
else if (guess < answer) {
return "You're too low!";
}
}
}
}






15 changes: 12 additions & 3 deletions call_apply_bind_exercise/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
Fix the following code:

```javascript
// var obj = {
// fullName: "Harry Potter",
// person: {
// sayHi: function(){
// return "This person's name is " + this.fullName
// }
// }
// }

var obj = {
fullName: "Harry Potter",
person: {
sayHi: function(){
return "This person's name is " + this.fullName
}
}.apply(obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use bind here:

var obj = {
   fullName: "Harry Potter",
   person: {
      sayHi: function() {
                     return "This person's name is " + this.fullName;
                  }
    }
}
obj.person.sayHi = obj.person.sayHi.bind(obj);

}
}
```

- List two examples of "array-like-objects" that we have seen.
-
-
- arguments
- result of DOM method such as getElementsByTagName

### Functions to write:

Expand Down
Loading