Commits

Ivan Savov  committed b3af029

Saving progress after a few lessons

  • Participants
  • Parent commits 3540a6a

Comments (0)

Files changed (16)

+
+SICPapp
+lessons/docs
+.DS_Store
+
+
+

File Links/Conway's Game of Life - Javascript-Canvas Implementation.webloc

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>URL</key>
+	<string>http://pmav.eu/stuff/javascript-game-of-life-v3.1.1/?autoplay=0&amp;trail=0&amp;grid=1&amp;colors=1&amp;zoom=1&amp;s=%5B{%2239%22:%5B110%5D},{%2240%22:%5B112%5D},{%2241%22:%5B109,110,113,114,115%5D}%5D</string>
+</dict>
+</plist>
 
-=== Learn to code === 
+Learn to code 
+=============
 
+JavaScript is the programming language of the web.
+It is good.
 
+
+=== Links ===
+
+http://eloquentjavascript.net/chapter2.html
+

File gab.js

-
-
-// LESSON1
-
-// exemple d'objet 
-var gab = { prenom: "Gabriel",
-            nom: "Poirier",
-            say_full_name: function () { 
-                console.log("My name is " + this.prenom + " " + this.nom);  
-            }    
-          };
-
-// ajouter une proprieté
-gab.age = 31
-
-// example of a function
-var addnums = function (x,y) {   console.log("first input is " + x);
-                                 console.log("second input is " + y);
-                                 return (x+y);    } 
-
-/// another object
-var ivan = { first_name : "Ivan" , last_name : "Savov" } 
-ivan.get_full_name = function ( ) { return this.first_name + " " + this.last_name; }
-
-// function 
-var mult = function ( a , b , c ) { return a * b * c ; }
-
-var connect_words = function ( a , b , c ) { return a + " " + b + " " + c  ; }
-
-
-// example object with some logic
-var question = {  
-   prompt: "What is 2*3?",
-   correctAnswer: 6,
-   checkAnswer: function (ans){ 
-        return ans === this.correctAnswer; 
-   },
-   showResponse: function (ans) {
-        if (this.checkAnswer(ans)) {
-            return "Correct answer!";
-        }
-        else {
-            return "Wrong bitch!";
-        };
-   }
-};
-
-
-// example for loop
-var sum = 0;
-var n;
-for( n=1 ; n <= 10 ;  n = n+1 ){
-    sum = sum + n;
-}
-
-
-// intro to lists
-var names  = [ "John", "Mary", "Joe" ];     
-
-
-
-
-
-
-
-// LESSON3
-
-var IvanSavov = { nom : "Savov" , prenom : "Ivan" } ;
-undefined
-IvanSavov
-Object {nom: "Savov", prenom: "Ivan"}
-IvanSavov.nom
-"Savov"
-IvanSavov.prenom
-"Ivan"
-IvanSavov.objet
-undefined
-IvanSavov.prenom + IvanSavov.nom
-"IvanSavov"
-var IS = { nom : "Savov" , prenom : "Ivan" } ;
-undefined
-is.nom
-ReferenceError: is is not defined
-var is = { nom : "Savov" , prenom : "Ivan" } ;
-undefined
-is =  
-SyntaxError: Unexpected token }
-is.nom
-"Savov"
-is.prenom
-"Ivan"
-is["nom"]
-"Savov"
-var is = { nom : "Savov" , prenom : "Ivan" } ;
-undefined
-var vec =
-SyntaxError: Unexpected token }
-var vec = [3,2,1]
-undefined
-vec
-[3, 2, 1]
-vec lenght
-SyntaxError: Unexpected identifier
-vec.lenght
-undefined
-lenght
-ReferenceError: lenght is not defined
-vec.length
-3
-vec[1]
-2
-vec
-[3, 2, 1]
-vec.0
-SyntaxError: Unexpected number
-vec[0]
-3
-var n 
-undefined
-n = 0
-0
-vec[0]
-3
-vec[n]
-3
-vec[1,2,3]
-undefined
-vec[0] + vec [1] + vec [2]
-6
-vec[1] + vec [2]
-3
-var vec2 = [ 1,2,3,4,5,6,7,8,9 ]
-undefined
-vec = 
-SyntaxError: Unexpected token }
-vec2
-[1, 2, 3, 4, 5, 6, 7, 8, 9]
-var sum = 0
-undefined
-for (n=0; n < 9 ; n = n+1 ) { sum = sum + vec2[n] }  
-45
-for (n=0; n < 9 ; n = n+1 ) { 
-   console.log( "maintentant on est " + n );
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0
-maintentant on est 1
-maintentant on est 2
-maintentant on est 3
-maintentant on est 4
-maintentant on est 5
-maintentant on est 6
-maintentant on est 7
-maintentant on est 8
-90
-for (n=0; n < 9 ; n = n+1 ) { 
-   console.log( "maintentant on est " + n );
-     console.log ( vec2[n] )
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0
-1
-maintentant on est 1
-2
-maintentant on est 2
-3
-maintentant on est 3
-4
-maintentant on est 4
-5
-maintentant on est 5
-6
-maintentant on est 6
-7
-maintentant on est 7
-8
-maintentant on est 8
-9
-135
-vec2
-[1, 2, 3, 4, 5, 6, 7, 8, 9]
-vec2[2]
-3
-vec2[n]
-undefined
-n
-9
-vec2.length
-9
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   console.log( "maintentant on est " + n );
-   console.log ( vec2[n] )
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0
-1
-maintentant on est 1
-2
-maintentant on est 2
-3
-maintentant on est 3
-4
-maintentant on est 4
-5
-maintentant on est 5
-6
-maintentant on est 6
-7
-maintentant on est 7
-8
-maintentant on est 8
-9
-180
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0 et vec2 de n est 1
-maintentant on est 1 et vec2 de n est 2
-maintentant on est 2 et vec2 de n est 3
-maintentant on est 3 et vec2 de n est 4
-maintentant on est 4 et vec2 de n est 5
-maintentant on est 5 et vec2 de n est 6
-maintentant on est 6 et vec2 de n est 7
-maintentant on est 7 et vec2 de n est 8
-maintentant on est 8 et vec2 de n est 9
-225
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0 et vec2 de n est 1
-maintentant on est 1 et vec2 de n est 2
-maintentant on est 2 et vec2 de n est 3
-maintentant on est 3 et vec2 de n est 4
-maintentant on est 4 et vec2 de n est 5
-maintentant on est 5 et vec2 de n est 6
-maintentant on est 6 et vec2 de n est 7
-maintentant on est 7 et vec2 de n est 8
-maintentant on est 8 et vec2 de n est 9
-45
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
-   sum = sum + vec2[n]; 
-}  
-maintentant on est 0 et vec2 de n est 1
-maintentant on est 1 et vec2 de n est 2
-maintentant on est 2 et vec2 de n est 3
-maintentant on est 3 et vec2 de n est 4
-maintentant on est 4 et vec2 de n est 5
-maintentant on est 5 et vec2 de n est 6
-maintentant on est 6 et vec2 de n est 7
-maintentant on est 7 et vec2 de n est 8
-maintentant on est 8 et vec2 de n est 9
-45
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   sum = sum + vec2[n]; 
-}  
-45
-var vec2 = [ 1,2,3,4,5,6,7,8,9,10 ]
-undefined
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   sum = sum + vec2[n]; 
-}  
-55
-var vec_sum = function ( vec2 ) { 
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   sum = sum + vec2[n]; 
-}  } ;
-undefined
-vec_sum
-function ( vec2 ) { 
-sum=0;
-for (n=0; n < vec2.length ; n = n+1 ) { 
-   sum = sum + vec2[n]; 
-}  }
-vec_sum ( vec2 ) 
-undefined
-var vec_sum = function ( vec2 ) { 
-  sum=0;
-  for (n=0; n < vec2.length ; n = n+1 ) { 
-     sum = sum + vec2[n]; 
-  }
-  return sum ;
-} ;
-undefined
-vec_sum (vec2 )
-55
-
-
-
-

File lessons/README.md

+
+
+
+JavaScript lessons
+==================
+
+Basics
+
+1. language basics
+2. arrays and dicts
+3. functions
+4. itertion (for / while)
+5. control flow
+
+
+Dom
+
+6. reading and writing text on a webpage
+7. 
+
+
+
+
+
+

File lessons/canvas_game.html

+<!DOCTYPE html>
+<html>
+
+  <head>
+    <title>Canvas demo</title>
+    <meta name="author"      content="Gabriel Poirier" />    
+    <meta name="description" content="A tutorial on the use of HTML canvas element." />
+  </head>
+  
+  <body>
+
+    <!-- Conteny HTML de la page -->
+    <h1>Canvas demo</h1>
+    <canvas id="lecanvas"></canvas>
+    
+    
+    <!-- JavaScript -->
+    <script type='text/javascript'>
+    
+        // settings 
+        var CANVAS_WIDTH  = 480;
+        var CANVAS_HEIGHT = 320;
+        var FPS = 20;
+
+        //         
+        var canvas = document.getElementById('lecanvas');
+        canvas.width = CANVAS_WIDTH; 
+        canvas.height = CANVAS_HEIGHT;
+        var ctx = canvas.getContext("2d");
+
+
+        // definition of the Player object
+        var Player = function(options){
+
+            // properties
+            this.x = 50;
+            this.y = 270;
+            this.width = 20;
+            this.height = 30;
+            this.color = "#333";
+            
+            // methods
+            this.draw = function() {
+                ctx.fillStyle = this.color;
+                ctx.fillRect(this.x, this.y, this.width, this.height);
+            }
+            this.move_left  = function() { this.x = this.x-5; };
+            this.move_right = function() { this.x = this.x+5; };
+            this.move_up    = function() { this.y = this.y-5; };
+            this.move_down  = function() { this.y = this.y+5; };
+            
+        };
+        
+        
+        player = new Player();
+        
+        
+        
+        function handle_keypress(e) {
+            console.log("key pressed");
+            e = e || window.event;
+            
+            console.log( e.keyCode );
+            if (e.keyCode == '37') {                   // left arrow
+                player.move_left();
+            } else if (e.keyCode == '38') {            // up arrow
+                player.move_up();
+            } else if (e.keyCode == '39') {            // right arrow
+                player.move_right();
+            } else if (e.keyCode == '40') {            // down arrow
+                player.move_down();
+            }
+        }
+        
+        function draw_game() {
+          ctx.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
+          player.draw();
+        }
+
+        // setup key binding
+        document.onkeydown = handle_keypress;
+        
+        setInterval(function() {
+          draw_game();
+        }, 1000/FPS);
+    </script>
+
+  </body>
+</html>

File lessons/cut_material.js

+
+
+We saw that a function can be regarded as a pattern for the local evolution of a process, 
+and we classified, reasoned about, and performed simple algorithmic analyses of some common 
+patterns for processes as embodied in functions. 
+
+    / // running time of algorithms
+    / // --------------------------
+    / // For example, suppose you have an array of numbers 
+    / // grades = [98,95,90,89, ... 42,40]
+    / //      // suppose this array represents the grades of all ther
+    / //      // other students in a class you are taking
+    / //
+    / // task: given your grade x, find your rank in you class.
+    / // suppose the function `findrank` does this computation 
+
+    findrank(99, grades)        // 1    because 99 would be the top grade, you would be first in the class!
+    findrank(96, grades)        // 2 
+
+    / // let n denote the number of stuents in your class
+    / //
+    / // linear search
+    / // A simple implementation of findrank,
+    / //      rank =1; check first grade, if greater retrun rank, else rank +1 and check next grade
+    / // will take on the order of n steps to complete
+    / //
+    / // binary search
+    / // A better implementation (binary search) of find rank
+    / // could take only log(n) steps to complete
+
+    / // two different algorithms can be used to implement the same function
+    / // the alorithms are equivalen in terms of what they compute,
+    / // byt they differ in the numbe rof stpes they require to compute the answer
+
+
+

File lessons/example1--a-full-application.html

+<div class="wrap"> 
+    <h1>Todo<span>, no fuss lists</span></h1> 
+    <input placeholder="Add a todo" type="text" id="item" /> 
+    <button id="go">Save</button> 
+    <span class="help">* tap to delete</span> 
+    
+    <ul id="tudu_list"> 
+    </ul> 
+</div>
+
+<script type="text/javascript">
+    var tudu_list = document.getElementById('tudu_list'); 
+    var item = document.getElementById('item'); 
+    var new_li; 
+    var new_obj = {}; 
+    function prependElement(parentID,child) { 
+        parent=parentID; 
+        parent.insertBefore(child,parent.childNodes[0]); 
+    } 
+    function remove(element){ 
+        element.parentNode.removeChild(element); 
+    } 
+    function deleteItem(){ 
+        var answer = confirm('Sure you want to remove this?'); 
+        if(answer){ 
+            var deleteId = this.getAttribute('rel'); 
+            remove(this); 
+        } 
+    } 
+    function addItem(){ 
+        if(item.value !== ''){ 
+            new_li = document.createElement('li'); 
+            new_li.innerHTML = item.value; 
+            prependElement(tudu_list, new_li); 
+            new_li.onclick = deleteItem; 
+            item.value = ''; 
+        } 
+    } 
+
+    function callAdd(e){ 
+        if(event.keyCode == 13){ 
+            addItem(); 
+        } 
+    } 
+    item.onkeyup = function(e){ callAdd(e) }; 
+    document.getElementById('go').onclick = addItem; 
+</script>
+

File lessons/flower_of_life.html

+<!DOCTYPE html>
+<html>
+
+  <head>
+    <title>The flower of life</title>
+    <meta name="author"      content="Gabriel Poirier" />    
+    <meta name="description" content="A tutorial on the use of functions and abstraction." />
+  </head>
+  
+  <body>
+
+    <!-- Conteny HTML de la page -->
+    <h1>The flower of life</h1> 
+    (<a href="http://en.wikipedia.org/wiki/Flower_of_Life">info</a>) 
+    <br/>
+    
+    <canvas id="lecanvas"></canvas>
+    
+    <!-- JavaScript -->
+    <script type='text/javascript'>
+    
+        // settings 
+        var CANVAS_WIDTH  = 480;
+        var CANVAS_HEIGHT = 320;
+
+        // geometry
+        var C30 = Math.cos( 30*Math.PI/180 );
+        var S30 = Math.sin( 30*Math.PI/180 );
+
+        //         
+        var canvas = document.getElementById('lecanvas');
+        canvas.width = CANVAS_WIDTH; 
+        canvas.height = CANVAS_HEIGHT;
+        var ctx = canvas.getContext("2d");
+
+
+
+
+        // definition of the Player object
+        var Circle = function(options){
+
+            options || (options = {});
+            // properties
+            this.radius = options.radius || 30;
+            this.x = CANVAS_WIDTH/2;
+            this.y = CANVAS_HEIGHT/2;
+            this.color = "#333";
+            
+            // methods
+            this.draw_circle = function() {
+                ctx.fillStyle = this.color;
+                ctx.beginPath();
+                ctx.arc(this.x, this.y, this.radius, 0, 2*Math.PI);
+                ctx.stroke();
+            }
+            
+            
+            this.move_up    = function() { 
+                this.y = this.y-this.radius; 
+            };
+            this.move_down  = function() { 
+                this.y = this.y+this.radius; 
+            };
+            this.move_down_left  = function() { 
+                this.y = this.y + S30*this.radius; 
+                this.x = this.x - C30*this.radius; 
+            };
+            this.move_down_right  = function() { 
+                this.y = this.y + S30*this.radius; 
+                this.x = this.x + C30*this.radius; 
+            };
+            
+        };
+        
+        
+        
+        life = new Circle();
+        
+        life.draw_circle();
+        life.move_up();
+        life.draw_circle();
+        life.move_down_left();
+        life.draw_circle();
+        life.move_down();        
+        life.draw_circle();
+        life.move_down_right();
+        life.draw_circle();    
+        
+        
+    </script>
+
+  </body>
+</html>

File lessons/gab.js

+
+
+// LESSON1
+
+// exemple d'objet 
+var gab = { 
+    prenom: "Gabriel",
+    nom: "Poirier",
+    say_full_name: function () { 
+                console.log("My name is " + this.prenom + " " + this.nom);  
+    }    
+};
+
+// ajouter une proprieté
+gab.age = 31
+
+// example of a function
+var addnums = function (x,y) {   console.log("first input is " + x);
+                                 console.log("second input is " + y);
+                                 return (x+y);    } 
+
+/// another object
+var ivan = { first_name : "Ivan" , last_name : "Savov" } 
+ivan.get_full_name = function ( ) { 
+    return this.first_name + " " + this.last_name; 
+}
+
+// function 
+var mult = function ( a , b , c ) { return a * b * c ; }
+
+var connect_words = function ( a , b , c ) { return a + " " + b + " " + c  ; }
+
+
+// example object with some logic
+var question = {  
+   prompt: "What is 2*3?",
+   correctAnswer: 6,
+   checkAnswer: function (ans){ 
+        return ans === this.correctAnswer; 
+   },
+   showResponse: function (ans) {
+        if (this.checkAnswer(ans)) {
+            return "Correct answer!";
+        }
+        else {
+            return "Wrong bitch!";
+        };
+   }
+};
+
+
+// example for loop
+var sum = 0;
+var n;
+for( n=1 ; n <= 10 ;  n = n+1 ){
+    sum = sum + n;
+}
+
+
+// intro to lists
+var names  = [ "John", "Mary", "Joe" ];     
+
+
+
+
+
+
+
+// LESSON3
+
+var IvanSavov = { nom : "Savov" , prenom : "Ivan" } ;
+undefined
+IvanSavov
+Object {nom: "Savov", prenom: "Ivan"}
+IvanSavov.nom
+"Savov"
+IvanSavov.prenom
+"Ivan"
+IvanSavov.objet
+undefined
+IvanSavov.prenom + IvanSavov.nom
+"IvanSavov"
+var IS = { nom : "Savov" , prenom : "Ivan" } ;
+undefined
+is.nom
+ReferenceError: is is not defined
+var is = { nom : "Savov" , prenom : "Ivan" } ;
+undefined
+is =  
+SyntaxError: Unexpected token }
+is.nom
+"Savov"
+is.prenom
+"Ivan"
+is["nom"]
+"Savov"
+var is = { nom : "Savov" , prenom : "Ivan" } ;
+undefined
+var vec =
+SyntaxError: Unexpected token }
+var vec = [3,2,1]
+undefined
+vec
+[3, 2, 1]
+vec lenght
+SyntaxError: Unexpected identifier
+vec.lenght
+undefined
+lenght
+ReferenceError: lenght is not defined
+vec.length
+3
+vec[1]
+2
+vec
+[3, 2, 1]
+vec.0
+SyntaxError: Unexpected number
+vec[0]
+3
+var n 
+undefined
+n = 0
+0
+vec[0]
+3
+vec[n]
+3
+vec[1,2,3]
+undefined
+vec[0] + vec [1] + vec [2]
+6
+vec[1] + vec [2]
+3
+var vec2 = [ 1,2,3,4,5,6,7,8,9 ]
+undefined
+vec = 
+SyntaxError: Unexpected token }
+vec2
+[1, 2, 3, 4, 5, 6, 7, 8, 9]
+var sum = 0
+undefined
+for (n=0; n < 9 ; n = n+1 ) { sum = sum + vec2[n] }  
+45
+for (n=0; n < 9 ; n = n+1 ) { 
+   console.log( "maintentant on est " + n );
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0
+maintentant on est 1
+maintentant on est 2
+maintentant on est 3
+maintentant on est 4
+maintentant on est 5
+maintentant on est 6
+maintentant on est 7
+maintentant on est 8
+90
+for (n=0; n < 9 ; n = n+1 ) { 
+   console.log( "maintentant on est " + n );
+     console.log ( vec2[n] )
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0
+1
+maintentant on est 1
+2
+maintentant on est 2
+3
+maintentant on est 3
+4
+maintentant on est 4
+5
+maintentant on est 5
+6
+maintentant on est 6
+7
+maintentant on est 7
+8
+maintentant on est 8
+9
+135
+vec2
+[1, 2, 3, 4, 5, 6, 7, 8, 9]
+vec2[2]
+3
+vec2[n]
+undefined
+n
+9
+vec2.length
+9
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   console.log( "maintentant on est " + n );
+   console.log ( vec2[n] )
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0
+1
+maintentant on est 1
+2
+maintentant on est 2
+3
+maintentant on est 3
+4
+maintentant on est 4
+5
+maintentant on est 5
+6
+maintentant on est 6
+7
+maintentant on est 7
+8
+maintentant on est 8
+9
+180
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0 et vec2 de n est 1
+maintentant on est 1 et vec2 de n est 2
+maintentant on est 2 et vec2 de n est 3
+maintentant on est 3 et vec2 de n est 4
+maintentant on est 4 et vec2 de n est 5
+maintentant on est 5 et vec2 de n est 6
+maintentant on est 6 et vec2 de n est 7
+maintentant on est 7 et vec2 de n est 8
+maintentant on est 8 et vec2 de n est 9
+225
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0 et vec2 de n est 1
+maintentant on est 1 et vec2 de n est 2
+maintentant on est 2 et vec2 de n est 3
+maintentant on est 3 et vec2 de n est 4
+maintentant on est 4 et vec2 de n est 5
+maintentant on est 5 et vec2 de n est 6
+maintentant on est 6 et vec2 de n est 7
+maintentant on est 7 et vec2 de n est 8
+maintentant on est 8 et vec2 de n est 9
+45
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   console.log( "maintentant on est " + n  + " et vec2 de n est " + vec2[n] );
+   sum = sum + vec2[n]; 
+}  
+maintentant on est 0 et vec2 de n est 1
+maintentant on est 1 et vec2 de n est 2
+maintentant on est 2 et vec2 de n est 3
+maintentant on est 3 et vec2 de n est 4
+maintentant on est 4 et vec2 de n est 5
+maintentant on est 5 et vec2 de n est 6
+maintentant on est 6 et vec2 de n est 7
+maintentant on est 7 et vec2 de n est 8
+maintentant on est 8 et vec2 de n est 9
+45
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   sum = sum + vec2[n]; 
+}  
+45
+var vec2 = [ 1,2,3,4,5,6,7,8,9,10 ]
+undefined
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   sum = sum + vec2[n]; 
+}  
+55
+var vec_sum = function ( vec2 ) { 
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   sum = sum + vec2[n]; 
+}  } ;
+undefined
+vec_sum
+function ( vec2 ) { 
+sum=0;
+for (n=0; n < vec2.length ; n = n+1 ) { 
+   sum = sum + vec2[n]; 
+}  }
+vec_sum ( vec2 ) 
+undefined
+var vec_sum = function ( vec2 ) { 
+  sum=0;
+  for (n=0; n < vec2.length ; n = n+1 ) { 
+     sum = sum + vec2[n]; 
+  }
+  return sum ;
+} ;
+undefined
+vec_sum (vec2 )
+55
+
+
+
+

File lessons/langs.json

+
+{ ".coffee":      {"name": "coffeescript", "symbol": "#"},
+  ".litcoffee":   {"name": "coffeescript", "symbol": "#", "literate": true},
+  ".md.js":       {"name": "javascript", "symbol": "//", "literate": true},
+  "Cakefile":     {"name": "coffeescript", "symbol": "#"},
+  ".rb":          {"name": "ruby", "symbol": "#"},
+  ".py":          {"name": "python", "symbol": "#"},
+  ".tex":         {"name": "tex", "symbol": "%"},
+  ".latex":       {"name": "tex", "symbol": "%"},
+  ".dtx":         {"name": "tex", "symbol": "%"},
+  ".sty":         {"name": "tex", "symbol": "%"},
+  ".cls":         {"name": "tex", "symbol": "%"},
+  ".js":          {"name": "javascript", "symbol": "//"},
+  ".java":        {"name": "java", "symbol": "//"},
+  ".groovy":      {"name": "groovy", "symbol": "//"},
+  ".scss":        {"name": "scss", "symbol": "//"},
+  ".cpp":         {"name": "cpp", "symbol": "//"},
+  ".php":         {"name": "php", "symbol": "//"},
+  ".hs":          {"name": "haskell", "symbol": "--"},
+  ".erl":         {"name": "erlang", "symbol": "%"},
+  ".hrl":         {"name": "erlang", "symbol": "%"},
+  ".md":          {"name": "markdown", "symbol": ""},
+  ".markdown":    {"name": "markdown", "symbol": ""},
+  ".less":        {"name": "scss", "symbol": "//"},
+  ".h":           {"name": "objectivec", "symbol": "//"},
+  ".m":           {"name": "objectivec", "symbol": "//"},
+  ".n":           {"name": "nemerle", "symbol": "//"},
+  ".mm":          {"name": "objectivec", "symbol": "//"},
+  ".scala":       {"name": "scala", "symbol": "//"},
+  ".cs":          {"name": "cs", "symbol": "//"},
+  ".as":          {"name": "actionscript", "symbol": "//"},
+  ".scpt":        {"name": "applescript", "symbol": "--"},
+  ".applescript": {"name": "applescript", "symbol": "--"},
+  ".sh":          {"name": "bash", "symbol": "#"},
+  ".clj":         {"name": "clojure", "symbol": ";"},
+  ".cmake":       {"name": "cmake", "symbol": "#"},
+  ".d":           {"name": "d", "symbol": "//"},
+  ".p":           {"name": "delphi", "symbol": "//"},
+  ".pp":          {"name": "delphi", "symbol": "//"},
+  ".pas":         {"name": "delphi", "symbol": "//"},
+  ".bat":         {"name": "dos", "symbol": "@?rem"},
+  ".btm":         {"name": "dos", "symbol": "@?rem"},
+  ".cmd":         {"name": "dos", "symbol": "@?rem"},
+  ".go":          {"name": "go", "symbol": "//"},
+  ".ini":         {"name": "ini", "symbol": ";"},
+  ".lisp":        {"name": "lisp", "symbol": ";"},
+  ".lua":         {"name": "lua", "symbol": "--"},
+  ".mel":         {"name": "mel", "symbol": "//"},
+  ".pl":          {"name": "perl", "symbol": "#"},
+  ".pm":          {"name": "perl", "symbol": "#"},
+  ".pod":         {"name": "perl", "symbol": "#"},
+  ".t":           {"name": "perl", "symbol": "#"},
+  ".r":           {"name": "r", "symbol": "#"},
+  ".rc":          {"name": "rust", "symbol": "//"},
+  ".rs":          {"name": "rust", "symbol": "//"},
+  ".sql":         {"name": "sql", "symbol": "--"},
+  ".vala":        {"name": "vala", "symbol": "//"},
+  ".vapi":        {"name": "vala", "symbol": "//"},
+  ".vbe":         {"name": "vbscript", "symbol": "'"},
+  ".vbs":         {"name": "vbscript", "symbol": "'"},
+  ".wsc":         {"name": "vbscript", "symbol": "'"},
+  ".wsf":         {"name": "vbscript", "symbol": "'"},
+  ".vhdl":        {"name": "vhdl", "symbol": "--"}
+}

File lessons/lesson1--language-basics.js

+
+A quick intro to JS and CS 
+==========================
+
+We concentrated in chapter 1 on computational 
+processes and on the role of functions in program design. 
+
+
+    var x, y, ans;   // define the variables `x`, `y`, and `ans` 
+    
+    / // Defining a function called add
+    var add = function(x,y) {
+        return x+y;                     // add two numbers 
+    };
+    
+    / // Defining another function called mult
+    var mult = function(x,y) {
+        return x*y;                     // mulitiply two numbers 
+    };
+    
+    ans = add(3,4);         // calling add
+    / // the ouput of add(3,4) is 7, so now ans is 7
+
+
+We saw how to use primitive data (numbers) 
+
+    x=4;
+    y=5;
+
+
+and primitive operations (arithmetic operations), 
+
+    ans = x*y;      // ans is 20
+
+how to combine functions to form compound functions through composition, 
+
+    / // to compute  2*3 + 4*5 using the functions `add` and `mult` defined above we woudl write
+    ans = add( mult(2,3), mult(4,5) );
+
+conditionals, 
+
+    var x, descr;     // suppose we want to compute a `descr`iption of the number x by a string  
+                    
+    if (x===0) {
+        descr = "zero";
+    } else if (x>0) {
+        descr = "positive";
+    } else if (x<0) {
+        descr = "negative";
+    } 
+
+    descr // descr is now either "zero", "positive", or "negative" conditional on x
+
+
+and the use of parameters, 
+
+    var linear_combination = function(a,b,x,y) {    // definiong a function with four parameters
+        return a*x + b*y;
+    }
+
+
+
+We also saw that higher-order functions enhance the power of our language by enabling us to manipulate, 
+and thereby to reason in terms of, general methods of computation. 
+
+    / // example of a function that returns a function as an output
+    var make_incrementor = function(n) {
+        return function (x) { return x+n; };
+    }
+
+    / // calling make_incrementor returns a function,
+    var incby2 = make_incrementor(2);     // the var incby2 now contains output of make_incremntor 
+    / // inc2 is a function
+
+    ans = incby2(10);       // ans is now 12
+
+
+This is much of the essence of programming.
+
+

File lessons/lesson1--language-basics_morewords.js

+A quick intro to CS in JS
+=========================
+
+A programming language is a set of instructions we use to tell a computer what to do. Like all languages, programming languages have strict rules about syntax (the otder of the words) and punctuation (where to use ";", for example). Unlike a human who will understand the meaning of instructions which are not "gramatically correct," a computer will
+balk immediately if you ever give it an instruction that does not obey 
+the syntax rules More specifically, it will throw a `SyntaxError`.
+
+Let's talk about `JavaScript` as a language. 
+Like any language, `JavaScript` consists of words.
+Words are identifiers for the different concepts in the language.
+Some words are nouns (represent things) and some words are verbs (represent actions). Some words refer to temporary made up `var`iables that we create for our needs.
+
+
+Example
+-------
+
+Consider the following example:
+
+	var x;
+    var y;
+    
+    x = 2;
+    y = Math.sqrt(x);
+
+In this snippet of `JavaScript` code, we define two variables `x` and `y`,
+then give the variable `x` the value `2` and then call the function `sqrt`, which is part of the `Math` module. The `Math` module is an example of a noun (an object) that comes built in with the `JavaScript` 
+language. The `Math` object contains lots of useful math functions.
+Using these built in functions, we can represent any math computation.
+
+
+---
+
+More interestingly, we can create our own functions that perform and sequence of desired operations:
+
+    / // Defining a function called `double`
+    var double = function(x) {  return 2*x; };
+
+    / // applying the function to the input 3
+    y = double(3);    // 6
+    
+    
+    / // Defining another function called mult
+    var mult = function(x,y) {
+        return x*y;  // mulitiply two numbers 
+    };
+    
+    y = mult(3,4);		// 12
+
+
+We can combine functions to form compound functions
+
+    y = mult( 5 , double(3) ); 		// 30 
+
+JavaScript also has conditional statements.
+Suppose we want to compute a `descr`iption of the number x as a string:
+
+    var x, descr;     
+                    
+    if (x===0) {
+        descr = "zero";
+    } else if (x>0) {
+        descr = "positive";
+    } else if (x<0) {
+        descr = "negative";
+    } 
+
+    descr 
+    
+The variable `descr` is now either `"zero"`, `"positive"`, or `"negative"` conditional on `x`.
+
+---
+
+
+Note the syntax for defining new functions, because functions are the 
+most important building block in programming.
+A function has parameters, and a body: 
+
+	/ // definiong a function `myfun` with three parameters a, b, b
+    / // which does stuff1 and stuff2 and returns stuff3
+    var myfun = function(a,b,c) {    // function body starts here
+        / // do stuff 1 with a b c
+        / // do stuff 2 with a b c and whatever happened in stuff1
+        return stuff3;		 	
+    }  // function body ends here
+
+
+Whenever you call `myfun` with inputs a, b, c, it will do its stuff,
+and return as an output the value of stuff3 (whatever that expression may be). 
+
+If you understand functions, then you understand the essence of programming.
+
+---
+
+Now since we are done so quickly with chapter 1, I figured I can show you
+some crazy stuff about higher-order functions which allow us to create functions that return functions! 
+
+    / // example of a function that returns a function as an output
+    var make_incrementor = function(n) {
+        return function (x) { return x+n; };
+    }
+
+    / // calling make_incrementor returns a function,
+    var incby2 = make_incrementor(2);   
+    / // incby2 is a function 
+
+    y = incby2(10);       //  12
+
+
+Yeah, so don't be fooled now. There is a lot of stuff to learn still, but I wanted to intorudce the main actors in the `JavaScript` language:
+the nouns like `x` and `y`, and the `Math` object,
+and the verbs like `sqrt`, `double`, `make_incrementor`, and `incby2`.
+

File lessons/lesson2--js-builtin-data-structures.js

+
+
+JS data structures
+==================
+
+
+In this lesson we will focus on the data structures which are
+built into the `JavaScript` language. These include arrays (lists of things),
+and objects (associative arrays).
+
+
+Arrays
+------
+
+
+    var list = [ 1, 2, 3, 4];
+
+    list.length
+    ▶ 4
+
+
+
+
+Objects
+-------
+
+
+    var obj = { joe:10, jane:20 };
+
+
+

File lessons/mkhtml.sh

+#!/usr/bin/env bash
+
+echo "Using docco to convert .js source files to .html"
+
+docco -e ".litjs" -c docs/docco_custom.css  lesson*.js
+
+

File lessons/session1_vars_functions.js

+
+x= 2 
+2
+x
+2
+x3 = x4
+ReferenceError: x4 is not defined
+GET chrome-search://thumb/http://google.ca/  thumbnail.js:65
+x4 = (4 * x )
+8
+3x * 3x 
+SyntaxError: Unexpected token ILLEGAL
+3*x * 3*x 
+36
+3x = 3*x
+SyntaxError: Unexpected token ILLEGAL
+x3 = 3*x
+6
+x3 * x3
+36
+squared = function ( x ) {
+SyntaxError: Unexpected end of input
+squared = function ( x ) {return x*x ; } 
+function ( x ) {return x*x ; }
+squred (9)
+ReferenceError: squred is not defined
+squared ( 9 )
+81
+divide = fun
+ReferenceError: fun is not defined
+divide = function (x , y ) {return x / y ; }
+function (x , y ) {return x / y ; }
+divide 81
+SyntaxError: Unexpected number
+divide ( 81 )
+NaN
+divide ( 81 , 9 )
+9
+divide ( 81 , 3 ) 
+27
+divide ( 4 , 3 ) 
+1.3333333333333333
+divide ( 4 , 98 ) 
+0.04081632653061224
+divide ( 4 , 1452398 ) 
+0.000002754066034241303
+Math.PI
+3.141592653589793
+Math.sin
+function sin() { [native code] }
+Math.sqrt ( 4 )
+2
+quadratique = function  ( a , b , c ) { return  ( - b + Math.sqrt (b*b - 4*a*c)) / (2*a) ; } 
+function ( a , b , c ) { return  ( - b + Math.sqrt (b*b - 4*a*c)) / (2*a) ; }
+quadratique ( 1 , 0 , -4 )
+2
+quadratique ( 1 , 0 , 4 )
+NaN
+
+