JavaScript Exercise 1a
Background Resources
- JavaScript Guide for JavaScript v1.8
- The canonical reference guide to the JavaScript language, for the Mozilla Developer Network. This is the recommended text for this part of the course.
Practicing JavaScript
Look at the JavaScript guide and use the JavaScript console in your browser to experiment with the language. Try out function definitions and array manipulations. Try the following:
- 4*6
- r=1/3
- s=Math.sqrt(10);
- function fac(n){if(n<=1)return 1;else return n*fac(n-1)}
- fac(4)
- fac
- twice=function(n){return n+n}
- twice(4)
- twice("4");
- arr=[0,1,2,3,4];
- arr[5]=5;
- arr[0]=9
- arr
- for(i in arr)arr[i]=i*i;
- for(i=0; i<arr.length; i++)arr[i]=i*i; //same as previous
- arr
- s="Hello COMP6017";
- s[0]
- marks={comp3016: 64, comp3001: 75, comp1003: 49}
- marks.comp3016
- marks["comp3001"]
- alert("Hello there: "+new Date());
- "Hello there".substring(4);
- for(i in window)console.log(i);