Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from maxogden/newpuzzles

add 4 new puzzles and instructions
  • Loading branch information...
commit 12a2297a67aba331eff936732695b863ddace482 2 parents 6e9eb09 + dcdaa54
@EastBayJS authored
View
19 1.js
@@ -0,0 +1,19 @@
+// problem: why does Ralph only bark once?
+// fix it to make Ralph bark twice!
+
+var Dog = function( name ) {
+ this.name = name
+}
+
+Dog.prototype.bark = function() {
+ console.log( this.name )
+}
+
+// make a new instance of a Dog
+var ralph = new Dog('Ralph')
+
+// make Ralph bark once immediately
+ralph.bark()
+
+// in 1 second we want Ralph to bark again
+setTimeout( ralph.bark , 1000 )
View
14 2.js
@@ -0,0 +1,14 @@
+// problem: why does it log out out 1000?
+// fix it to log 100, 200, 300, 400, 500 etc
+
+// loops 10 times from 0 - 1000 in increments of 100
+for (var i = 0; i < 1000; i += 100) {
+ waitFor(i, function then() {
+ console.log(i)
+ })
+}
+
+// this will run a callback function after waiting milliseconds
+function waitFor(milliseconds, callback) {
+ setTimeout(callback, milliseconds)
+}
View
13 3.js
@@ -0,0 +1,13 @@
+// problem: why is it logging out 0? it should be 12
+// since 4 * 4 is 16, 2 * 2 is 4 and 16 - 4 is 12
+// fix it to log out 12!
+
+function square(num) {
+ result = num * num
+ return result
+}
+
+result = square(4)
+result2 = square(2)
+var subtracted = result - result2
+console.log(subtracted)
View
19 4.js
@@ -0,0 +1,19 @@
+// problem: it is adding all of the numbers to the evenNumbers array
+// even though it should only add even numbers
+// fix it to only add even numbers!
+
+var evenNumbers = []
+
+function addEvensOnly(num) {
+ if (num % 2 === 0)
+ console.log(num, 'is even, adding!')
+ evenNumbers.push(num)
+}
+
+addEvensOnly(0)
+addEvensOnly(1)
+addEvensOnly(2)
+addEvensOnly(3)
+addEvensOnly(4)
+
+console.log('even numbers: ', evenNumbers)
View
22 README.md
@@ -1,4 +1,24 @@
javascript-puzzles
==================
-Improve your JavaScript skills by correcting the errors in this code
+Improve your JavaScript skills by correcting the errors in this code.
+
+You can run this in the browser by copy and pasting each exercise into your browsers JavaScript console:
+
+![browser](screenshots/browser.png)
+
+Or on the command line using [node.js](http://nodejs.org):
+
+![node](screenshots/node.png)
+
+## contributing
+
+If you have an idea for a puzzle that will teach someone an important JS concept then please submit it as a pull request!
+
+## license
+
+BSD
+
+## credits
+
+some puzzles adapted from http://liamkaufman.com/blog/2012/09/09/common-javascript-errors/
View
BIN  screenshots/browser.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  screenshots/node.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.