



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the lecture notes for csci 100 'think like computers' course, fall 2008. It covers the basics of javascript variables, memory cells, and data manipulation. How to declare and assign variables, store values in memory cells, and reuse variables. It also discusses the use of prompts with defaults and localizing changes using variables. Additionally, it touches upon the importance of converting strings to numbers using parsefloat function.
Typology: Slides
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Variables VARIABLE = prompt("PROMPT MESSAGE", ""); firstName = prompt("Please enter your name", "");
Write to the web page: document.write("MESSAGE TO BE DISPLAYED " + VARIABLE + " MORE MESSAGE" + ...); document.write("Hello " + firstName + ", welcome to my Web page.");
the browser displays this output just as it does any other text if the text contains HTML tags, the browser will interpret the tags and format the text accordingly
document.write("Hello " + firstName + ", welcome to my Web page.");
assuming the variable firstName has been assigned "Dave", the browser would execute the statement to produce Hello Dave, welcome to my Web page.
which would be displayed by the browser as Hello Dave , welcome to my Web page.
some syntax errors are ignored by the browser e.g., misspelling an HTML tag name most JavaScript syntax errors will generate an error message document.write("This example is illegal since the string is broken across lines");
yields: Error: unterminated string literal
document.write("The value of x is " x);
yields: Error: missing ) after argument list
valid: tempInFahr SUM current_age Sum2Date x invalid: 2hotforU salary$ two words "sum_to_date"
when a JavaScript assignment is executed,
firstName = prompt("Please enter your name", "");
the value entered by the user (e.g., "Dave") is stored in a memory cell associated with the variable firstName
any future reference to the variable name evaluates to the value stored in its associated memory cell
the first pair of statements
the second pair of statements
VARIABLE = prompt("PROMPT MESSAGE", "");
animal = prompt("Enter a kind of animal:", "cow"); sound = prompt("What kind of sound does it make?", "moo");
("E-I-E-I-O" Æ "Eeyigh-Eeyigh-Oh")
Math.pow(2, 10) Æ 210 = 1024 Math.pow(2, -1) Æ 2 -1^ = 0. Math.pow(9, 0.5) Æ 9 0.5^ = 3
note: this function has no inputs; it returns a different number each call
Math.random() Æ 0. Math.random() Æ 0. Math.random() Æ 0.