Skip to content

Instantly share code, notes, and snippets.

View slopeofhope81's full-sized avatar

Steve Lim slopeofhope81

View GitHub Profile
@slopeofhope81
slopeofhope81 / gist:9199861
Created February 24, 2014 23:57
todo app using local storage
$(function(){
$("#add").click(function(){
var description=$("#description").val();
if(description === ""){
$("#alert").html("<strong>Warning</strong> You left the todo app!");
$("#alert").fadeIn().delay(1000).fadeOut();
return false;
}
$("#todos").prepend("<li><input type='checkbox' name='checkbox'>"+ description+ "</li>");
$("#form")[0].reset();
@slopeofhope81
slopeofhope81 / gist:9114994
Last active August 29, 2015 13:56
playing with jQuery for DOM manipulation.
var KEY={
UP: 38,
DOWN: 40,
W: 87,
S: 83,
};
var pingpong = {};
pingpong.ball = {
speed: 5,
x: 150,
@slopeofhope81
slopeofhope81 / gist:9113201
Created February 20, 2014 13:11
my latest endeavor with javascript
function loadasync(url){
var head=document.getElementsByTagName("head")[0];
var script=document.createElement("script");
script.src=url;
head.appendChild(script);
}
function urlArg(){
var args = {};
var query = window.location.search.substring(1);
@slopeofhope81
slopeofhope81 / gist:9093298
Created February 19, 2014 14:35
I made this quiz app that has following: 1)radio button choices 2)it will show score upon completion 3)can show any # of questions and choices4)tally the user's score and remove everything else in the form
<html>
<head><!--html-->
<title>example1</title>
<link rel="stylesheet" type="text/css" href="do.css">
</head>
<body>
<div id="point"></div>
<div id="question"></div>
<form name="radioAnswers">
@slopeofhope81
slopeofhope81 / gist:9072649
Created February 18, 2014 15:03
Now I understand the power of bind method how it will always run in the given context.
For example, take a look at the first example below:
1)(function(){
var cart={
item: "product1",
price: 35.50,
quantity: 2,
buying: function(){
alert("you bought"+this.item);
}
};
@slopeofhope81
slopeofhope81 / gist:9057028
Created February 17, 2014 19:14
Making a quiz questions #1
var allQuestions = [];
allQuestions[0]={
question: "what is your name?",
choices:["steve", "kevin", "chloe","haeseong"],
correctAnswer: 1
};
allQuestions[1]={
question: "what is your passion?",
choices:["programmer", "teacher", "scientist","home builder"],
correctAnswer: 1
@slopeofhope81
slopeofhope81 / gist:8976024
Created February 13, 2014 14:32
jquery DOM manipulation #2
$(document).ready(function () {
$(".section").click(checkForCode);
function getRandom(n) {
return Math.floor(Math.random() * n);
}
var hideCode = function () {
var num = getRandom(4);
$(".section").each(function (index, value) {
if (num == index) {
@slopeofhope81
slopeofhope81 / gist:8968066
Last active August 29, 2015 13:56
jquery button interaction=DOM manipulation(it makes change to the DOM's representation of the page in the browser.
$(document).ready(function(){
$("#move_up").click(function(){
$("#change_me").animate({top:100}, 1000);
});
$("#move_down").click(function(){
$("#change_me").animate({top:400},1000)
});
$("#change_color").click(function(){
$("#change_me").css("background-color","purple");
});
@slopeofhope81
slopeofhope81 / gist:8845219
Last active August 29, 2015 13:56
defineProperty is JS
To set attributes of a property or to create a new property with the specified attributes.
var a = {};
Object.defineProperty(0, "x", {value:1, writable: true, enumerable:false, configurable: true});
Guess what this does?
Also changing this (data property to an accessor property) =>
Object.defineProperty(0, "x", { get: function(){ return 0} });
@slopeofhope81
slopeofhope81 / gist:8826927
Created February 5, 2014 16:04
write a map and forEach function
write a map and forEach function:
function forEach(array, action){
for (var i =0; i < array.length; i++){
action(array[i]));
}
};
function map(func,array){
var result =[];