From c43df7c33529e939697c3bca788cb6cec24ccb90 Mon Sep 17 00:00:00 2001 From: preeme Date: Mon, 31 Jul 2017 17:50:27 -0700 Subject: [PATCH 01/11] completed tests and functions --- testing_exercise/testing.js | 41 +++++++++++++++++++++++++ testing_exercise/testingSpec.js | 53 ++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/testing_exercise/testing.js b/testing_exercise/testing.js index e69de29b..0687d95a 100644 --- a/testing_exercise/testing.js +++ b/testing_exercise/testing.js @@ -0,0 +1,41 @@ +function replaceWith(str, char, replaced) { + return str.split(char).join(replaced); +} + +function expand(array, num) { + var newArray = []; + for (var i = 0; i < num; i++) { + for(var j = 0; j < array.length; j++) { + newArray.push(array[j]); + } + } + return newArray; +} + +function acceptNumbersOnly() { + var isTrue = true; + for (var i = 0; i < arguments.length; i++) { + if (arguments[i] === parseInt(arguments[i])) { + isTrue = isTrue && true; + } + else isTrue = false; + + } + return isTrue; +} + +function mergeArrays(array1, array2) { + var newArray = array1.concat(array2); + return newArray.sort(function(a, b) { + return a - b; + }); +} + +function mergeObjects(obj1, obj2) { + for (var key in obj2) { + if (obj2.hasOwnProperty(key)){ + obj1[key] = obj2[key]; + } + } + return obj1; +} diff --git a/testing_exercise/testingSpec.js b/testing_exercise/testingSpec.js index aef56b1d..e91532d0 100644 --- a/testing_exercise/testingSpec.js +++ b/testing_exercise/testingSpec.js @@ -1,3 +1,54 @@ var expect = chai.expect; -// WRITE YOUR TESTS HERE! \ No newline at end of file +describe('replaceWith', function(){ + it('Basic function replace letters', function() { + expect(replaceWith('awesome', 'e', 'z')).to.equal('awzsomz'); + }); + it('Case sensitive', function() { + expect(replaceWith('Foo', 'F', 'B')).to.equal('Boo'); + }); +}); + +describe('expand', function() { + it('Basic function with numbers', function(){ + expect(expand([1, 2, 3], 3)).to.deep.equal([1, 2, 3, 1, 2, 3, 1, 2, 3]); + }); + + it('Basic function with strings', function(){ + expect(expand(['foo', 'test'], 1)).to.deep.equal(['foo', 'test']); + }); +}); + +describe('acceptNumbersOnly', function() { + it('Basic function', function() { + expect(acceptNumbersOnly(1, 'foo')).to.equal(false) + }); + + it('Basic function true', function() { + expect(acceptNumbersOnly(1, 2, 3, 4, 5)).to.equal(true); + }); + + it('Basic function NaN', function() { + expect(acceptNumbersOnly(1, 2, NaN, 4, 5)).to.equal(false); + }); +}); + +describe('mergeArrays', function() { + it('Basic function merges arrays', function() { + expect(mergeArrays([2, 1], [3, 4])).to.deep.equal([1, 2, 3, 4]); + }); +}); + +describe('mergeObjects', function() { + var obj1= { + name: "Foo", + num: 33 + } + var obj2 = { + test: "thing", + num: 55 + } + it('Basic function merge objects', function() { + expect(mergeObjects(obj1, obj2)).to.deep.equal({name: 'Foo', test: 'thing', num: 55}); + }); +}); From 3cd9d0edd2d6383d8c62c496ae60e9c5ea0529cf Mon Sep 17 00:00:00 2001 From: preeme Date: Tue, 1 Aug 2017 21:49:30 -0700 Subject: [PATCH 02/11] still working on bonus questions --- recursion_exercise/recursion.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/recursion_exercise/recursion.js b/recursion_exercise/recursion.js index e69de29b..b235093e 100644 --- a/recursion_exercise/recursion.js +++ b/recursion_exercise/recursion.js @@ -0,0 +1,34 @@ +function productOfArray(arr) { + if (arr.length === 0) return 1; + return arr[0] * productOfArray(arr.splice(1)); +} + +function collectStrings(obj) { + var newArray = []; + function helper(myObj) { + for (var key in myObj) { + if (typeof myObj[key] === 'object') { + helper(myObj[key]); + } + else { + newArray.push(myObj[key]); + } + } + } + helper(obj); + return newArray; +} + +function contains(obj, src) { + var isFound = false; + for (var key in obj) { + if (typeof obj[key] === 'object') { + isFound = contains(obj[key], src); + } + else if (obj[key] === src) { + return true; + } + if (isFound) return true; + } + return false; +} From afc12b5229bea02402872a710721dc15740b802f Mon Sep 17 00:00:00 2001 From: preeme Date: Wed, 2 Aug 2017 23:08:04 -0700 Subject: [PATCH 03/11] still working on more functions --- lodash_exercise/lodash.js | 172 ++++++++++++++++++++++++++++---------- 1 file changed, 129 insertions(+), 43 deletions(-) diff --git a/lodash_exercise/lodash.js b/lodash_exercise/lodash.js index 483d734a..902698e1 100644 --- a/lodash_exercise/lodash.js +++ b/lodash_exercise/lodash.js @@ -1,57 +1,143 @@ -function drop(){ - +function drop(arr, num){ + if (num === 0) return arr; + if (!num) num = 1; + return arr.slice(num); } -function fromPairs(){ - +function fromPairs(arr){ + var newObj = {}; + for (var i = 0; i < arr.length; i++) { + newObj[arr[i][0]] = arr[i][1]; + } + return newObj; } -function head(){ - +function head(arr){ + return arr.shift(); } -function take(){ - +function take(arr, num){ + if (num === 0) return []; + if (!num) return [arr[0]]; + return arr.slice(0, num); } -function takeRight(){ - +function takeRight(arr, num){ + if (num === 0) return []; + if (!num) return [arr.length]; + if (num > arr.length -1) return arr; + return arr.slice(num - 1, arr.length); } function union(){ - -} - -function zipObject(){ - -} - -function includes(){ - -} - -function sample(){ - -} - -function cloneDeep(){ - -} - -function sumBy(){ - -} - -function inRange(){ - -} - -function has(){ - -} - -function omit(){ - + var array = []; + for (var i = 0; i < arguments.length; i++) { + array = array.concat(arguments[i]); + } + return array.filter(function(val, index, arr) { + return arr.indexOf(val) === index; + }); +} + +function zipObject(arr1, arr2){ + var myObj = {}; + for (var i = 0; i < arr1.length; i++) { + myObj[arr1[i]] = arr2[i]; + } + return myObj; +} + +function includes(collection, src){ + if (arguments.length > 2) return false; + if (typeof collection === 'string') { + if (collection.match(src)) return true; + return false; + } + if (Array.isArray(collection)) { + for (var i = 0; i < collection.length; i++) { + if (collection[i] === src) return true; + else return false; + } + } + if (typeof collection === 'object') { + for (var key in collection) { + if (collection[key] === src) return true; + return false; + } + } +} + +function sample(arr){ + return arr[Math.floor(Math.random() * arr.length)]; +} + +function cloneDeep(val){ + if (Array.isArray(val)) { + var newVal = []; + for (var i = 0; i < val.length; i++){ + newVal = newVal.concat(cloneDeep(val[i])); + } + return newVal; + } + else { + var newVal = {}; + for (var key in val) { + newVal[key] = val[key]; + } + return newVal; + } +} + +function sumBy(arr, key){ + return arr.reduce(function(all, item, index){ + if (typeof key === 'function') { + return all + key(item); + } + return all + item[key]; + }, 0); +} + +function inRange(num, start, end){ + if (start > end) { + if (num > end & num < start) return true; + } + if (typeof end === 'undefined') { + end = start; + start = 0; + } + if (num > start && num < end) return true; + else return false; +} + +function has(obj, path){ + var isTrue = true; + if (Array.isArray(path)) { + for (var i = 0; i < path.length; i++) { + for (var key in obj) { + if (obj[key] === path[i]) isTrue && true; + else isTrue && false; + } + } + } + else { + for (var key in obj) { + if (obj[key] === path) isTrue && true; + else isTrue && false; + } + } + return isTrue; +} + +function omit(obj, path){ + var newObj = obj; + for (var i = 0; i < path.length; i++) { + for (var key in newObj) { + if (newObj[key] === path) { + delete newObj[key]; + } + } + } + return newObj; } function pick(){ From ff7834c939e6c3f4189a3423f82f986ed54162ea Mon Sep 17 00:00:00 2001 From: preeme Date: Fri, 4 Aug 2017 09:15:48 -0700 Subject: [PATCH 04/11] still need to finish arrow keys --- canvas_exercise/shapes_game/index.js | 112 +++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 5 deletions(-) diff --git a/canvas_exercise/shapes_game/index.js b/canvas_exercise/shapes_game/index.js index 0de5f18a..d4f1d09b 100644 --- a/canvas_exercise/shapes_game/index.js +++ b/canvas_exercise/shapes_game/index.js @@ -1,15 +1,55 @@ window.addEventListener("load", function() { - function clear(ctx, width, heigt) { + function clear(ctx, width, height) { + ctx.clearRect(0, 0, width, height); } - function drawRandomShape(ctx, width, height) { + function drawRandomShape(ctx) { + //0 = white triangle 1 = red triangle 2 = white square 3 = red square + var shapes = [0, 1, 2, 3]; + var x = Math.floor(Math.random() * (650 - 100) + 100); + var y = Math.floor(Math.random() * (650 - 100) + 100); + + if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 0) { + ctx.fillStyle = 'white'; + ctx.beginPath(); + ctx.moveTo(x, x); + ctx.lineTo(x, x + 70); + ctx.lineTo(x + 70, x + 70); + ctx.fill(); + ctx.closePath(); + return 0; + } + else if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 1) { + ctx.fillStyle = 'red'; + ctx.beginPath(); + ctx.moveTo(x, x); + ctx.lineTo(x, x + 70); + ctx.lineTo(x + 70, x + 70); + ctx.fill(); + ctx.closePath(); + return 1; + } + else if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 2) { + ctx.fillStyle = 'white'; + ctx.fillRect(x, y, 70, 70); + return 2; + } + else { + ctx.fillStyle = 'red'; + ctx.fillRect(x, y, 70, 70); + return 3; + } } function drawGameStartText(ctx, width, height, score) { + ctx.fillStyle = 'white'; + ctx.font = '36px serif'; + ctx.fillText('Press the space bar to start a new game', width, height); } function restartGame(ctx, width, height) { + } var canvas = document.getElementById("shapes-game"), @@ -28,9 +68,71 @@ window.addEventListener("load", function() { canvas.width = width; canvas.height = height; + //white shapes + // ctx.fillStyle = 'white'; + // ctx.fillRect(300, 20, 70, 70); + // ctx.beginPath(); + // ctx.moveTo(30, 30); + // ctx.lineTo(30, 100); + // ctx.lineTo(100, 100); + // ctx.fill(); + // ctx.closePath(); + // //red Shapes + // ctx.fillStyle = 'red'; + // ctx.fillRect(200, 400, 70, 70); + // ctx.beginPath(); + // ctx.moveTo(200, 200); + // ctx.lineTo(200, 270); + // ctx.lineTo(270, 270); + // ctx.fill(); + // ctx.closePath(); + // //clear shapes, triangle must be cleared like a square + // ctx.clearRect(200, 200, 100, 100); + // //Game start text + // ctx.fillStyle = 'white'; + + //timer - document.addEventListener("keyup", function() { - + drawGameStartText(ctx, 100, 400); + document.addEventListener("keyup", function(event) { + if (event.keyCode === 32) { + var countdown = 30; + var timer = setInterval(count, 1000); + //0 = white triangle (up) 1 = red triangle(left) 2 = white square(right) 3 = red square(down) + function count() { + countdown--; + timerSpan.innerHTML = countdown; + clear(ctx, width, height); + if (countdown === 0) { + timerSpan.innerHTML = countdown; + clearInterval(timer); + } + } + } + else { + if (event.keyCode === 37) { + if (randomShape === 1) Number(scoreSpan.innerHTML += 1); + else Number(scoreSpan.innerHTML -= 1); + } + else if (event.keyCode === 38) { + if (randomShape === 0) Number(scoreSpan.innerHTML += 1); + else Number(scoreSpan.innerHTML -= 1); + } + else if (event.keyCode === 39) { + if (randomShape === 2) Number(scoreSpan.innerHTML += 1); + else Number(scoreSpan.innerHTML -= 1); + } + else if (event.keyCode === 40){ + if (randomShape === 3) Number(scoreSpan.innerHTML += 1); + else Number(scoreSpan.innerHTML - 1); + } + else Number(scoreSpan.innerHTML -= 1); + } + + //once key gets pressed it runs functions attached + //waits for next key to be pressed + // + //match expectedKey to expectedKeysMap + drawRandomShape(ctx); }); }); - From a5ca53883b5b706622a214db5005fd07825e1c9b Mon Sep 17 00:00:00 2001 From: preeme Date: Sun, 6 Aug 2017 17:27:57 -0700 Subject: [PATCH 05/11] finished, used solution to help me with else if statement in the event listener --- canvas_exercise/shapes_game/index.js | 97 +++++++++++----------------- 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/canvas_exercise/shapes_game/index.js b/canvas_exercise/shapes_game/index.js index d4f1d09b..7ec74d8e 100644 --- a/canvas_exercise/shapes_game/index.js +++ b/canvas_exercise/shapes_game/index.js @@ -10,6 +10,7 @@ window.addEventListener("load", function() { var x = Math.floor(Math.random() * (650 - 100) + 100); var y = Math.floor(Math.random() * (650 - 100) + 100); + //{white0: 38, red1: 40, red0: 37, white1: 39} if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 0) { ctx.fillStyle = 'white'; ctx.beginPath(); @@ -18,7 +19,7 @@ window.addEventListener("load", function() { ctx.lineTo(x + 70, x + 70); ctx.fill(); ctx.closePath(); - return 0; + return 'white0'; } else if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 1) { ctx.fillStyle = 'red'; @@ -28,17 +29,17 @@ window.addEventListener("load", function() { ctx.lineTo(x + 70, x + 70); ctx.fill(); ctx.closePath(); - return 1; + return 'red0'; } else if (shapes.indexOf(Math.floor(Math.random() * (4 - 0))) === 2) { ctx.fillStyle = 'white'; ctx.fillRect(x, y, 70, 70); - return 2; + return 'white1'; } else { ctx.fillStyle = 'red'; ctx.fillRect(x, y, 70, 70); - return 3; + return 'red1'; } } @@ -46,10 +47,14 @@ window.addEventListener("load", function() { ctx.fillStyle = 'white'; ctx.font = '36px serif'; ctx.fillText('Press the space bar to start a new game', width, height); + if (score !== undefined) { + ctx.fillText('Score: ' + score, width + 225, height + 50); + } } function restartGame(ctx, width, height) { - + countdown = 30; + scoreSpan.innerHTML = 0; } var canvas = document.getElementById("shapes-game"), @@ -63,76 +68,46 @@ window.addEventListener("load", function() { expectedKeysMap = {white0: 38, red1: 40, red0: 37, white1: 39}, timerSpan = document.getElementById("time-remaining"), scoreSpan = document.getElementById("score-val"), - seconds = 3, + countdown = 30, intervalId; canvas.width = width; canvas.height = height; - //white shapes - // ctx.fillStyle = 'white'; - // ctx.fillRect(300, 20, 70, 70); - // ctx.beginPath(); - // ctx.moveTo(30, 30); - // ctx.lineTo(30, 100); - // ctx.lineTo(100, 100); - // ctx.fill(); - // ctx.closePath(); - // //red Shapes - // ctx.fillStyle = 'red'; - // ctx.fillRect(200, 400, 70, 70); - // ctx.beginPath(); - // ctx.moveTo(200, 200); - // ctx.lineTo(200, 270); - // ctx.lineTo(270, 270); - // ctx.fill(); - // ctx.closePath(); - // //clear shapes, triangle must be cleared like a square - // ctx.clearRect(200, 200, 100, 100); - // //Game start text - // ctx.fillStyle = 'white'; - - //timer - drawGameStartText(ctx, 100, 400); document.addEventListener("keyup", function(event) { - if (event.keyCode === 32) { - var countdown = 30; - var timer = setInterval(count, 1000); - //0 = white triangle (up) 1 = red triangle(left) 2 = white square(right) 3 = red square(down) - function count() { + if (!gameOn && event.keyCode === 32) { + gameOn = true; + clear(ctx, width, height); + expectedKey = expectedKeysMap[drawRandomShape(ctx)]; + intervalId = setInterval(function() { countdown--; - timerSpan.innerHTML = countdown; - clear(ctx, width, height); if (countdown === 0) { - timerSpan.innerHTML = countdown; - clearInterval(timer); + clearInterval(intervalId); + gameOn = false; + var endScore = +scoreSpan.innerHTML; + restartGame(); + clear(ctx, width, height); + drawGameStartText(ctx, 100, 400, endScore); } - } - } - else { - if (event.keyCode === 37) { - if (randomShape === 1) Number(scoreSpan.innerHTML += 1); - else Number(scoreSpan.innerHTML -= 1); - } - else if (event.keyCode === 38) { - if (randomShape === 0) Number(scoreSpan.innerHTML += 1); - else Number(scoreSpan.innerHTML -= 1); - } - else if (event.keyCode === 39) { - if (randomShape === 2) Number(scoreSpan.innerHTML += 1); - else Number(scoreSpan.innerHTML -= 1); + timerSpan.innerHTML = countdown; + }, 1000); + //0 = white triangle (up) 1 = red triangle(left) 2 = white square(right) 3 = red square(down) } - else if (event.keyCode === 40){ - if (randomShape === 3) Number(scoreSpan.innerHTML += 1); - else Number(scoreSpan.innerHTML - 1); + else if (gameOn && Object.values(expectedKeysMap).includes(event.keyCode)) { + if (expectedKey === event.keyCode) { + scoreSpan.innerHTML = Number(scoreSpan.innerHTML) + 1; + } + else { + scoreSpan.innerHTML = Number(scoreSpan.innerHTML) - 1; + } + clear(ctx, width, height); + expectedKey = expectedKeysMap[drawRandomShape(ctx)]; } - else Number(scoreSpan.innerHTML -= 1); - } + }); + drawGameStartText(ctx, 100, 400); //once key gets pressed it runs functions attached //waits for next key to be pressed // //match expectedKey to expectedKeysMap - drawRandomShape(ctx); - }); }); From 2133d7822ec83405fdee5c1ea2e9ba43490732db Mon Sep 17 00:00:00 2001 From: preeme Date: Mon, 7 Aug 2017 20:45:42 -0700 Subject: [PATCH 06/11] basic requirements, still working on design --- jquery_exercise/hack_clone.html | 46 +++++++++++++++++++++++++++++++++ jquery_exercise/hack_clone.js | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 jquery_exercise/hack_clone.html create mode 100644 jquery_exercise/hack_clone.js diff --git a/jquery_exercise/hack_clone.html b/jquery_exercise/hack_clone.html new file mode 100644 index 00000000..c3bc1f01 --- /dev/null +++ b/jquery_exercise/hack_clone.html @@ -0,0 +1,46 @@ + + + + + + + Hacker News + + + + + + + + +
+
+ title:
+
+ url:
+ + +
+
    +
  1. test site
  2. +
+
+ + + + diff --git a/jquery_exercise/hack_clone.js b/jquery_exercise/hack_clone.js new file mode 100644 index 00000000..e741fc52 --- /dev/null +++ b/jquery_exercise/hack_clone.js @@ -0,0 +1,46 @@ +$(function() { + var $sites = $("#sites"); + $("#news").hide(); + + $("form").on("submit", function(e) { + e.preventDefault(); + + var $title = $("#title"); + var titleText = $title.val(); + var $url = $("#url"); + var urlText = $url.val(); + // var $newStar = $("", { + // class: "glyphicon glyphicon-star-empty", + // ariaHidden: true + // }); + var $newLi = $("
  • ", { + + }); + $newLi.html(` + ${titleText} + `); + + // $sites.prepend($newStar); + $sites.append($newLi); + $title.val(""); + $url.val(""); + $("#news").hide(); + }); + $("#nav-submit").on("click", function() { + $("#news").show(); + }); + // + $(".glyphicon").on("click", function(e) { + if ($(".glyphicon").hasClass("glyphicon-star-empty")) { + $(".glyphicon").removeClass("glyphicon-star-empty").addClass("glyphicon-star"); + } + else { + $(".glyphicon").removeClass("glyphicon-star").addClass("glyphicon-star-empty"); + } + }); + //make it look nice + // + //favorites on click hide empty stars + // + +}); From 41c3644c7b2ac9889993b9666cb49301c931511f Mon Sep 17 00:00:00 2001 From: preeme Date: Mon, 7 Aug 2017 20:46:22 -0700 Subject: [PATCH 07/11] finished remaining basic problems --- lodash_exercise/lodash.js | 77 +++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/lodash_exercise/lodash.js b/lodash_exercise/lodash.js index 902698e1..c39ac4a2 100644 --- a/lodash_exercise/lodash.js +++ b/lodash_exercise/lodash.js @@ -129,43 +129,82 @@ function has(obj, path){ } function omit(obj, path){ - var newObj = obj; - for (var i = 0; i < path.length; i++) { - for (var key in newObj) { - if (newObj[key] === path) { - delete newObj[key]; - } + var newObj = {}; + for (var key in obj) { + if (path.indexOf(key) === -1) { + newObj[key] = obj[key]; } } return newObj; } -function pick(){ - +function pick(obj, path){ + var newObj = {}; + for (var key in obj) { + if (path.indexOf(key) !== -1) { + newObj[key] = obj[key]; + } + } + return newObj; } -function pickBy(){ - +function pickBy(obj, fn){ + var newObj = {}; + for (var key in obj) { + if (fn(obj[key])) { + newObj[key] = obj[key]; + } + } + return newObj; } -function omitBy(){ - +function omitBy(obj, fn){ + var newObj = {}; + for (var key in obj) { + if (!fn(obj[key])) { + newObj[key] = obj[key]; + } + } + return newObj; } -function padEnd(){ - +function padEnd(str, length, char){ + var newStr = ''; + if (str.length >= length) return str; + if (char === undefined) { + for (var i = 0; i < length - str.length; i++) { + newStr += ' '; + } + return str.concat(newStr); + } + for (var i = 0; i < length - str.length; i++) { + newStr += char[i % char.length]; + } + return str.concat(newStr); } -function repeat(){ - +function repeat(str, num){ + var newStr = ''; + if (num === 0) return newStr; + for (var i = 0; i < num; i++) { + newStr = newStr.concat(str); + } + return newStr; } function upperFirst(str){ - + return str[0].toUpperCase().concat(str.slice(1)); } -function flatten(){ - +function flatten(arr){ + var newArr = []; + for (var i = 0; i < arr.length; i++) { + if (Array.isArray(arr[i])) { + newArr = newArr.concat(arr[i]); + } + else newArr.push(arr[i]); + } + return newArr; } function zip(){ From 23458e331cda9070212ef3d566a61ba37f693321 Mon Sep 17 00:00:00 2001 From: preeme Date: Tue, 8 Aug 2017 16:32:22 -0700 Subject: [PATCH 08/11] initial commit --- ajax_with_jquery_exercise/hack_clone.html | 46 +++++++++++++++++++++++ ajax_with_jquery_exercise/hack_clone.js | 46 +++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 ajax_with_jquery_exercise/hack_clone.html create mode 100644 ajax_with_jquery_exercise/hack_clone.js diff --git a/ajax_with_jquery_exercise/hack_clone.html b/ajax_with_jquery_exercise/hack_clone.html new file mode 100644 index 00000000..c3bc1f01 --- /dev/null +++ b/ajax_with_jquery_exercise/hack_clone.html @@ -0,0 +1,46 @@ + + + + + + + Hacker News + + + + + + + + +
    +
    + title:
    +
    + url:
    + + +
    +
      +
    1. test site
    2. +
    +
    + + + + diff --git a/ajax_with_jquery_exercise/hack_clone.js b/ajax_with_jquery_exercise/hack_clone.js new file mode 100644 index 00000000..e741fc52 --- /dev/null +++ b/ajax_with_jquery_exercise/hack_clone.js @@ -0,0 +1,46 @@ +$(function() { + var $sites = $("#sites"); + $("#news").hide(); + + $("form").on("submit", function(e) { + e.preventDefault(); + + var $title = $("#title"); + var titleText = $title.val(); + var $url = $("#url"); + var urlText = $url.val(); + // var $newStar = $("", { + // class: "glyphicon glyphicon-star-empty", + // ariaHidden: true + // }); + var $newLi = $("
  • ", { + + }); + $newLi.html(` + ${titleText} + `); + + // $sites.prepend($newStar); + $sites.append($newLi); + $title.val(""); + $url.val(""); + $("#news").hide(); + }); + $("#nav-submit").on("click", function() { + $("#news").show(); + }); + // + $(".glyphicon").on("click", function(e) { + if ($(".glyphicon").hasClass("glyphicon-star-empty")) { + $(".glyphicon").removeClass("glyphicon-star-empty").addClass("glyphicon-star"); + } + else { + $(".glyphicon").removeClass("glyphicon-star").addClass("glyphicon-star-empty"); + } + }); + //make it look nice + // + //favorites on click hide empty stars + // + +}); From b0db5e7325222b40979d476e7abe21fd71fe4b5e Mon Sep 17 00:00:00 2001 From: preeme Date: Wed, 9 Aug 2017 11:22:14 -0700 Subject: [PATCH 09/11] progress --- ajax_with_jquery_exercise/hack_clone.html | 60 ++++++++++++-------- ajax_with_jquery_exercise/hack_clone.js | 67 ++++++++++------------- 2 files changed, 66 insertions(+), 61 deletions(-) diff --git a/ajax_with_jquery_exercise/hack_clone.html b/ajax_with_jquery_exercise/hack_clone.html index c3bc1f01..fb2e68b6 100644 --- a/ajax_with_jquery_exercise/hack_clone.html +++ b/ajax_with_jquery_exercise/hack_clone.html @@ -11,32 +11,46 @@ - +
    + + + + + + +
    -
    - title:
    -
    - url:
    - - -
    -
      -
    1. test site
    2. -
    +
    +
      +
    +
    + +