Skip to content
Browse files

add 4 new puzzles and instructions

  • Loading branch information...
1 parent 6e9eb09 commit dcdaa540cc05e9f9c0f09ad8c4b330c20fc94790 @maxogden committed
Showing with 86 additions and 1 deletion.
  1. +19 −0 1.js
  2. +14 −0 2.js
  3. +13 −0 3.js
  4. +19 −0 4.js
  5. +21 −1 README.md
  6. BIN screenshots/browser.png
  7. BIN screenshots/node.png
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.

0 comments on commit dcdaa54

Please sign in to comment.
Something went wrong with that request. Please try again.