CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -
TA Labs, Office Hours Laboratory Polices Lab Hours 2:30 PM - 4:20 PM, Monday and Friday at Room Oelman Hall TA Office Hours 4:40 PM - 5:40 PM, Monday and Friday at Room Russ Engineer Center By appointment – Please to Refer to CS 1150 Course Syllabus for Class and Laboratory Policies Zero tolerance policy for Academic Misconduct – All parties will get 0% marks CS Lab 2 - Exploring Number Systems2
JavaScript Programming Lab Overview Learn how to write Output Statements, use Message Boxes and Variables Gain an understanding of Conditional Statements Complete Part 1, 2, 3, 4 and 5 (Required for all Students) Extra Credit Question at the End (Worth 3 Points) Lab Due Date - Oct 28, :30 PM CS Lab 2 - Exploring Number Systems3
How to Submit JavaScript Programming Lab Use Pilot Page for this Weeks’s Submission Go to Pilot Course Page and Use Dropbox Submission Link to upload your files I should be able to run your programs. Please submit all your html files and answers/screenshots to pilot Use the checklist to make sure you submitted all files CS Lab 2 - Exploring Number Systems4
What is JavaScript CS Lab 2 - Exploring Number Systems5 Client-side Scripting Language Used to create Dynamic Web Pages Three ways to write JavaScript Code In HTML Header, within Tags In HTML Body, within Tags In Separate.JS file, within Tags
Writing Your First JavaScript Code CS Lab 2 - Exploring Number Systems6 document.write("Hello World"); alert("Hello World"); HTML Code HTML Header Code SCRIPT Tags HTML Body Writes in to HTML File Writes in to a Message Box
Helper HTML Code CS Lab 2 - Exploring Number Systems7 Use a new copy of this template for every section (part 1 – 4)
Part 2 Help CS Lab 2 - Exploring Number Systems8 Input you read through prompt boxes are Strings To perform arithmetic operations on numbers you read through prompt boxes, you need to first convert them to proper data types. var x = 1 – Define variable x and sets its value to 1 x = parseInt(x) – Converts the value stored in variable x to an Integer and stores it in variable x.
Part 3 Help CS Lab 2 - Exploring Number Systems9 var x = 1; if (x== 1) { document.write("x is " + x); } else { document.write("x is not 1"); } Simple conditional (if- else) statement written in JavaScript Run this to see how a conditional (if-else) statement works in JavaScript
Part 4 Help CS Lab 2 - Exploring Number Systems10 You Need to Do Two Tasks Task 1 – Write a Psudo-code or a Flow Chart to Convert Temperature from Celsius to Fahrenheit or from Fahrenheit to Celsius Task 2 – Write a JavaScript Program to Convert Temperature from Celsius to Fahrenheit or from Fahrenheit to Celsius
Part 4 Help Cont. CS Lab 2 - Exploring Number Systems11 You need minimum of three variables Look at the screenshots given at the end to have an idea about the inputs and the output You need to change the variables in the equations given in part 4 using the variables you defined to make temperature calculation work
Part 5 Help CS Lab 2 - Exploring Number Systems12 for (var i=0; i<2; i++) { alert("Hello " + i); } Simple for loop written in JavaScript Run this to see how a for loop works in JavaScript
Part 5 Help Cont. CS Lab 2 - Exploring Number Systems13 var counter = 0; document.write("Starting Loop" + " "); while (counter < 5) { document.write("Current Count : " + counter + " "); counter++; } document.write("Loop stopped"); Copy the code shown Identify what is; Loop initialization step Looping condition (test) Loop update statement Now replace the while loop with a for loop
Extra Credit Help CS Lab 2 - Exploring Number Systems14 Think the following three steps when writing the loop What number should you use at the loop initialization step What should be the loop test or looping condition What should be the loop updating statement Should you increase the loop condition variable or decrease it?
Questions ? If you have questions, please raise your hand, Colin or myself will come to help you CS Lab 2 - Exploring Number Systems15