JavaScript is a programming language that runs in browsers and is commonly used to control webpage interactions and customize the user experience. It can be embedded directly in HTML pages or linked as an external .js file. JavaScript code can be tested using tools like JSFiddle or the Chrome developer tools console. Basic JavaScript involves assigning values to variables, looking up values, and reassigning values. Functions are defined using the function keyword and parameters can be passed into functions.
2. JavaScript: What is it?
• A programming language that (commonly) works
client-side to control browser and website actions.
• Common uses:
– Screen movement
– Mouse events
– Pop up events (think notes & alerts)
– Validate forms
– Store information in cookies
– Customize experience for specific users
• Object-based (depending on who you talk to)
• Embeds directly into an HTML page or linked to as a
separate .js file.
3. How to code & test?
• http://jsfiddle.net/
• Chrome Tools: JavaScript Console
• Use Notepad++ to write JavaScript and save
with .js extension…
• …or just write it in your .html file!
– http://www.u.arizona.edu/~londiem/crossroads_t
yps_kairos-submission/home.html
6. Working with strings & statements
alert(“DON’T PANIC!”);
confirm(“Hurray for school!”);
prompt(“Want some ice cream?”);
7. Variables
• Used to store data.
• You can give a variable a value, and you can
change that value.
• Most JavaScript code you will work with is
simply a matter of assigning values to
variables, looking up those values, and
assigning new values.
8. Basic function syntax
var NAME = function (PARAMETER) {ACTION}
var square = function(number) { return number * number; };
alert(square(9));
9. Space is meaningless
var square = function(num) { return num * num; };
alert(square(9));
var square = function (num) {
return num * num;
};
alert(square(9));
10. Tips
• Check your " and ' quotes match
• Carefully nest things (if you open something,
close it)
• Take care with capitalisation
• Lay it out neatly - use tabs
• Be patient