Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -

Similar presentations


Presentation on theme: "CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -"— Presentation transcript:

1 CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne E-mail – wijeratne.2@wright.eduwijeratne.2@wright.edu Web Page - http://knoesis.org/researchers/sanjaya/http://knoesis.org/researchers/sanjaya/

2 TA Labs, Office Hours Laboratory Polices Lab Hours 2:30 PM - 4:20 PM, Monday at Room 320 - Oelman Hall TA Office Hours 4:45 PM - 5:45 PM, Monday at Room 316 - Russ Engineer Center By appointment – Please email to wijeratne.2@wright.eduwijeratne.2@wright.edu Refer to CS 1150 Course Syllabus for Class and Laboratory Policies Zero tolerance policy for Academic Misconduct – All parties will get 0% marks CS 1150 - Lab 8 – JavaScript Programming Lab 2

3 JavaScript Programming Lab Overview Learn how to write Output Statements, use Message Boxes and Variables Gain an understanding of Conditional Statements and Loops Complete Part 1, 2, 3, 4 and 5 (Write All Programs and Answer All Questions) Lab Due Date - Mar 24, 2013 11:55 AM 3 CS 1150 - Lab 8 – JavaScript Programming Lab

4 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 to pilot Use the checklist to make sure you have submitted all files 4 CS 1150 - Lab 8 – JavaScript Programming Lab

5 What is JavaScript 5 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 CS 1150 - Lab 8 – JavaScript Programming Lab

6 Writing Your First JavaScript Code 6 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 CS 1150 - Lab 8 – JavaScript Programming Lab

7 Helper HTML Code 7 Use a new copy of this whenever you need it CS 1150 - Lab 8 – JavaScript Programming Lab

8 Part 2 Help 8 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. CS 1150 - Lab 8 – JavaScript Programming Lab

9 Part 3 Help 9 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 CS 1150 - Lab 8 – JavaScript Programming Lab

10 Part 4 – Speed Conversion Program 10 You need to use if-else statements. Based on the input you receive from the user (‘M’ or ‘K’), decide which formula to execute to calculate the new speed. You need minimum of three variables Look at the screenshots given to have an idea about the inputs and the output CS 1150 - Lab 8 – JavaScript Programming Lab

11 Part 4 – Rock Paper Scissors Game 11 You need to use nested if-else statements. Look at the screenshots given to have an idea about the inputs and the output Think what are the inputs you want to store in variables Think about all possible outcomes that you may run into when playing this game (Draw, Player 1 Wins, Player 2 Wins) CS 1150 - Lab 8 – JavaScript Programming Lab

12 Part 4 – Rock Paper Scissors Game Cont. 12 The game has three outcomes. They are; Game ends in a draw (if both players input the same letter) Player 1 can win (There are 3 ways player one can win – Check what are they) Player 2 can win (If the game is not a tie (draw) nor won by Player 1, Player 2 wins) Try to implement this logic using nested if-else statements CS 1150 - Lab 8 – JavaScript Programming Lab

13 Part 5 Help 13 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 CS 1150 - Lab 8 – JavaScript Programming Lab

14 Part 5 Help Cont. 14 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 CS 1150 - Lab 8 – JavaScript Programming Lab

15 Part 5 – Rock Paper Scissors Tournament 15 You need to write a loop that runs 5 times You need to have variables to store how many games won by Player 1 and Player 2 when they play this game for five times After the program is run for five times, check who has most number of wins CS 1150 - Lab 8 – JavaScript Programming Lab

16 Additional Help 16 Look at JavaScript Presentations Slides discussed in class by Mr. Chris Fickert Read the JavaScript Book CS 1150 - Lab 8 – JavaScript Programming Lab

17 Questions ? If you have questions, please raise your hand, Colin or I will come to help you 17 CS 1150 - Lab 8 – JavaScript Programming Lab


Download ppt "CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -"

Similar presentations


Ads by Google