Download presentation
Presentation is loading. Please wait.
1
March 9, 2011CS 1921 JavaScript Debbie Bartlett March 9, 2011
2
CS 192 2 What is JavaScript? Purpose is to add interactivity to HTML pages Is a scripting language i.e. interpreted languages, not compiled Contains lines of executable computer code Usually embedded directly into HTML pages Does not require a license
3
March 9, 2011 CS 192 3 Calculator CALCULATOR VERSION 2 (Another Simple Calculator) Passing Arguments to a JavaScript Function 1.In the top box, put the first number 2.In the second box, put the second number 3.Click on the operation you wish performed on these numbers 4.The answer appears in the bottom box
4
March 9, 2011 CS 192 4 Another Simple Calculator Example JavaScript Calculator Version 2 function calculate(opCode) { with(document.calc) if(opCode == "+") result.value = eval(op1.value) + eval(op2.value); else if(opCode == "-") result.value = eval(op1.value) - eval(op2.value); else if(opCode == "*") result.value = eval(op1.value) * eval(op2.value); else if(opCode == "/") result.value = eval(op1.value) / eval(op2.value); } CALCULATOR VERSION 2 Passing Arguments to a JavaScript Function In the top box, put the first number In the second box, put the second number Click on the operation you wish performed on these numbers The answer appears in the bottom box
5
March 9, 2011 CS 192 5 Assignment Visit the following website: http://www.cs.colostate.edu/~cs192/Examples/index.html http://www.cs.colostate.edu/~cs192/Examples/index.html Click on an example JavaScript View the source Right click, view this frame only Right click, view source Look at source, find script language tag Create new web page with this source and link to your main page gedit or emacs file_name.html paste source in file_name and save ensure file_name is readable by all using chmod Use calculator tag in your home page Ensure this works Modify your JavaScript in some way For example, add button to square first number Ensure changes work Submit info requested in ramCT
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.