Skip to content

Instantly share code, notes, and snippets.

@Pcushing
Created June 27, 2012 02:56
Show Gist options
  • Save Pcushing/3001028 to your computer and use it in GitHub Desktop.
Save Pcushing/3001028 to your computer and use it in GitHub Desktop.
js week3 exercises
<!DOCTYPE html>
<head>
<title>Week 3 Exercises... sort of like yoga</title>
<script type="text/javascript" language="javascript" src="patrickCushing_allExercises.js"></script>
<!-- Just wanted to see what jquery was all about so feel free to remove this for ease of reading.
It would have been cooler if I'd gotten hide / expand working to show the code instead -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body>
<!-- I really need to figure out how forms work. -->
<!-- <form>
<h1>Greeter</h1>
<input type="text" name="firstName" size="10" label="First Name" />
<input type="text" name="lastName" size="10" />
<input type="button" value="Me say hello to you." onClick="hello(this.form)" /><br/>
</form -->>
<div data-role="page">
<div data-role="header">
<h2>Greeter</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
hello("Patrick","Cushing");
</script>
</ul>
</div> <!-- end content -->
<div data-role="header">
<h2>Favorite Number</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
favoriteNumber(5);
favoriteNumber(1);
favoriteNumber(4);
</script>
</ul>
</div>
<div data-role="header">
<h2>Pig Latin</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
pigLatin("nix");
pigLatin("apple");
pigLatin("stupid");
pigLatin("three");
pigLatin("quiet");
pigLatin("school");
</script>
</ul>
</div>
<div data-role="header">
<h2>Leap Years</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
leapYear(1983);
leapYear(1988);
leapYear(1900);
leapYear(2000);
</script>
</ul>
</div>
<div data-role="header">
<h2>Sum it up</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
sum([1,3,5,7,9]);
</script>
</ul>
</div>
<div data-role="header">
<h2>Title Case</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
titleCase("the great gatsby");
titleCase("liTTle reD Riding hOOD");
</script>
</ul>
</div>
<div data-role="header">
<h2>Factorial</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
factorial(5);
factorial(0);
</script>
</ul>
</div>
<div data-role="header">
<h2>Smiley</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
smiley({mood: "happy"});
smiley({mood: "sad"});
smiley({mood: "weird"});
</script>
</ul>
</div>
<div data-role="header">
<h2>Weather</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
weather("San Francisco");
weather("Chicago");
weather("Miami");
weather("Los Angeles");
weather("Anchorage");
</script>
</ul>
</div>
<div data-role="header">
<h2>Triangle</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
triangle([2,2,2]);
triangle([2,2,3]);
triangle([2,3,4]);
triangle([2,2,4]);
</script>
</ul>
</div>
<div data-role="header">
<h2>Instance Calculator</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
var calc = new Calculator();
calc.add(5,3);
calc.subtract(5,3);
calc.multiply(5,3);
calc.divide(8,5);
</script>
</ul>
</div>
<div data-role="header">
<h2>Extending Number with inWords()</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
var four = 4;
var seventeen = 17;
var fortySeven = 47;
var twoHundredSix = 206;
var sixThirteen = 613;
var nineHundredNinetyTwo = 992;
four.inWords();
seventeen.inWords();
fortySeven.inWords();
twoHundredSix.inWords();
sixThirteen.inWords();
nineHundredNinetyTwo.inWords();
</script>
</ul>
</div>
<div data-role="header">
<h2>Creating a Dictionary Class</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
var sharks = new Dictionary();
sharks.add({'Great white': 'lord of the sea'});
sharks.add('thresher');
sharks.add({'hammer head': 'a social shark'});
sharks.entries();
sharks.includes('Great white');
sharks.includes('mako');
sharks.add({'goblin': 'brings the funk'});
sharks.add('sharkThatDoesntExistWithGrInMiddle');
sharks.find('g');
sharks.find('gr');
</script>
</ul>
</div>
<div data-role="header">
<h2>Implementing Each for JS</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implementing-array-each'>" +
["peanut", "butter"].newEach(function(){ " + this + "</a></li>") }) + "</a></li>");
</script>
</ul>
</div>
<div data-role="header">
<h2>Implementing Collect for JS</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-collect'>" +
['Sally', 'Mary', 'Joe'].newCollect(function(){ return "I love " + this + "."; }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-collect'>" +
[1,2,3].newCollect(function(){ return this + 1; }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-collect'>" +
[1,2,3].newCollect(function(){ return null; }) + "</a></li>");
// This is giving [object, object] rather than [number, string]? How come?
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-collect'>" +
[1,'cat'].newCollect(function(){ return typeof this; }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-collect'>" +
[1,2,3].newCollect(function(){ }) + "</a></li>");
</script>
</ul>
</div>
<div data-role="header">
<h2>Implementing Count for JS</h2>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<script>
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-count'>" +
[1,2,3,4,5].newCount(function(){ if (this > 3){ return true; } }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-count'>" +
[1,2,3,4,5].newCount(function(){ }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-count'>" +
[1,2,3,4,5].newCount(function(){ return false; }) + "</a></li>");
document.write("<li><a href='http://socrates.devbootcamp.com/labs/ruby-intro/block-and-procs-and-lambdas/re-implement-array-count'>" +
[1,2,3,4,5].newCount(function(){ return true; }) + "</a></li>");
</script>
</ul>
</div>
</div> <!-- /Page -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment