Weeks 2 & 3
JavaScript for discrete computational structures
use a text editor (like notepad) or use a javascript editor (like notepad ++ , pspad, homesite, aptana, firebug, etc.)
put all javascript between <script> and </script>
<script>command1; command2; ...; commandn</script>
it is usually useful to write your code inside functions --
function myfunction(){command1; command2; ...; commandn}
input from user --
myvariable=prompt("hello")
output --
alert(string)
example: see here (using ANY browser other than IE7)
save in your class web folder
Handy things:
variables:
http://srufaculty.sru.edu/david.dailey/javascript/javascript.variable.html
conditionals
if(condition) {command1; command2; ...; commandn}or
if(condition){command1; command2; ...; commandn}else{commandk; commandk+1; ...; commandp}see also
http://srufaculty.sru.edu/david.dailey/javascript/conditional.html
loops
x=4; for (i=0;i<7;i++) {x=x+1} .... when done x will equal 11.see also
string concatenation and manipulation:
"hello "+"there person"+" number "+7+"!" is the same as "hello there person number 7!"
"hello".charAt(0) is the same as "h"
"hello".indexOf("h") is 0.
see also http://srufaculty.sru.edu/david.dailey/javascript/string.html
array management:
for several array methods, see http://srufaculty.sru.edu/david.dailey/javascript/array-works.html
examples:
if A=[0,9,"a",0,5,51] , then
A.length is 6
A[0] is 0 and A[2] is "a"
A.push(9) is [0,9,"a",0,5,51,9] (A is changed by the operation)
A.sort( ) yields [0,0,5,51,9,"a"] (A is changed by the operation) (see also sorting an associative array and these notes from javascirptkit.com )
A simple HTML/JavaScript editor (written in HTML and JavaScript)
Assignment #2?:
Jan. 26th -- beginning of class (Monday) -- handed in on paper
- pages 12 - 13; exercises 2a,2b,3b,3c,4a,4b,5,7a,8a.
- pages 31-35; exercises 1a, 1c, 1e, 1f, 3a-d, 6a, 6b, 8a, 8b, 15, 18.
Assignment #3?
Jan. 23 -- (Friday) -- end of day
Email me a link to your program (stored on class web space) that accepts as input any comma-delimited bag of strings and outputs just the set of unique elements.
Assignment #4
Jan. 29th (Thursday) -- end of day
e-mail me, as the text of the message (not an attachment), the source code of your program for assignment #3 reformulated as a function named uniq() which accepts comma delimited string as an input parameter and returns (as output) the set of unique elements. The program (function) must work in the context of this web page.
Assignment #5
Feb. 11 (Wednesday) -- end of day
Email me a link to your program (stored on class web space) that accepts as input any two sets (A and B) and outputs
- their intersection A∪B
- their union A∩B
- their symmetric difference
- the truth or falsity of the statements A⊂B and B⊂A.
- A - B
- B - A
Unicode chart for many mathematical symbols
Tuples, relations, strings, graphs, trees.