Exercise 1: Basic HTML and JavaScript

Similar documents
c122mar413.notebook March 06, 2013

CSC Web Programming. Introduction to JavaScript

Program Design Phase. Algorithm Design - Mathematical. Algorithm Design - Sequence. Verify Algorithm Y = MX + B

introjs.notebook March 02, 2014

COMS 469: Interactive Media II

Programming language components

JavaScript: Introduction to Scripting

By the end of this section of the practical, the students should be able to:

The first sample. What is JavaScript?

People = End Users & Programmers. The Web Browser Application. Program Design Phase. Algorithm Design -Mathematical Y = MX + B

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

JavaScript: The Basics

JavaScript: Introductionto Scripting

CHAPTER 5: JavaScript Basics 99

JAVASCRIPT BASICS. Type-Conversion in JavaScript. Type conversion or typecasting is one of the very important concept in

JavaScript CS 4640 Programming Languages for Web Applications

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

Agenda. My Introduction. CIS 154 Javascript Programming

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

(from Chapters 10/11 of the text)

Web Programming/Scripting: JavaScript

JavaScript CS 4640 Programming Languages for Web Applications

CHAPTER 6 JAVASCRIPT PART 1

JavaScript: Introduction, Types

JAVASCRIPT LESSON 4: FUNCTIONS

By the end of this section of the practical, the students should be able to:

Namma Kalvi.

JavaScript Introduction

3 The Building Blocks: Data Types, Literals, and Variables

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

Chapter 8 JavaScript/JScript: Introduction to Scripting 201

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

JavaScript s role on the Web

ORB Education Quality Teaching Resources

Chapter 1 Introduction to Computers and the Internet

Lecture 2. The variable 'x' can store integers, characters, string, float, boolean.

Place User-Defined Functions in the HEAD Section

COMP 110 Practice Exercises for Midterm Solutions

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

334 JavaScript/JScript: Functions Chapter 11. boss. worker1 worker2 worker3. Hierarchical boss function/worker function relationship.

Chapter 9 - JavaScript: Control Structures II

Introduction to JavaScript

<script type="text/javascript"> script commands </script>

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Command-driven, event-driven, and web-based software

CGS 3066: Spring 2015 JavaScript Reference

(Refer Slide Time: 01:40)

INTRODUCTION TO JAVASCRIPT

Chapter 7: Javascript: Control Statements. Background and Terminology. Background and Terminology. Background and Terminology

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved.

Webinar. The Lighthouse Studio Scripting Series. JavaScript Sawtooth Software, Inc.

5/19/2015. Objectives. JavaScript, Sixth Edition. Understanding Syntax Errors. Introduction to Debugging. Handling Run-Time Errors

Mobile Site Development

Current trends: Scripting (I) A bid part of interface design centers around dialogs

Lotus Using JavaScript in IBM Lotus Domino 7 Applications.

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 (

CISC 1600 Lecture 2.4 Introduction to JavaScript

COMP519 Practical 5 JavaScript (1)

Session 3: JavaScript - Structured Programming

Client-side Techniques. Client-side Techniques HTML/XHTML. Static web pages, Interactive web page: without depending on interaction with a server

Lesson 6: Introduction to Functions

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Notesc120Mar515.notebook. March 05, Next I want to change the logic to handle all four of these:

CITS1231 Web Technologies. JavaScript

JAVASCRIPT. Computer Science & Engineering LOGO

Session 6. JavaScript Part 1. Reading

HTML HTML/XHTML HTML / XHTML HTML HTML: XHTML: (extensible HTML) Loose syntax Few syntactic rules: not enforced by HTML processors.

Lesson 7: If Statement and Comparison Operators

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include

Programming for Experimental Research. Flow Control

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

What is PHP? [1] Figure 1 [1]

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

JOHNSON COUNTY COMMUNITY COLLEGE COURSE SYLLABUS WEB CRN Web Scripting: JavaScript I

Time: 3 hours. Full Marks: 70. The figures in the margin indicate full marks. Answer from all the Groups as directed. Group A.

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 12

Lab 1. Purpose. Assignment. Action Items/Programming Requirements

10.) Click on the Security tab in Internet Options. 11.) Then click on Trusted Sites. 12.) Click on the Custom level button.

Browser behavior can be quite complex, using more HTTP features than the basic exchange, this trace will show us how much gets transferred.

(from Chapter 10/11 of the text)

Web System and Technologies (Objective + Subjective)

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Lab 2 Population. Purpose. Assignment Lab 2 analyzes population growth of a town as well as compare the population growth of two towns.

<form>. input elements. </form>

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

Variables and Typing

A Web-Based Introduction

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

Session 16. JavaScript Part 1. Reading

COMS 469: Interactive Media II

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

Dynamism and Detection

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Coding in JavaScript functions

Transcription:

Exercise 1: Basic HTML and JavaScript Question 1: Table Create HTML markup that produces the table as shown in Figure 1. Figure 1 Question 2: Spacing Spacing can be added using CellSpacing and CellPadding to a table. Create HTML markup that produces the table as shown in Figure 2. Figure 2

Question 3: Form Create HTML markup that produces a form as shown in Figure 3. Note that when the button submit is clicked, the form will be submitted to an email address that you specify. Question 4 Figure 3 JavaScript is an interpreted scripting language. The code can be incorporated using the <script> tag to the html document as follows:

<script type= text/javascript > As the first example, the code document.writeln("<h1> Hello world </h1>"); simply displays the words Hello world using h1 header in the browser. <head> <title> First example </title> document.writeln("<h1> Hello world </h1>"); </head> <body> </body> </html> (a): Case sensitive? Using the above hello world example, test whether JavaScript is case sensitive. You can replace writeln by WRITELN to see the result. (b): Alert and prompt windows Two commonly used pop-ups in JavaScript are the alert and the prompt windows. Their formats for usage are as follows: var name = window.prompt ( Enter your name please, myname ); window.alert ( hello +name); User is requested to enter the name through the prompt window and a greeting message is displayed using the alert window. <head> <title> Second example </title> var name = window.prompt ("Enter your name please", "myname"); window.alert ("Hello! " + name); </head> <body> </body> </html> 1. A prompt window is displayed in which the user enters the name. 2. After the user presses OK, a greeting message is displayed.

Modify the above example, so that two prompt windows appear one by one. The first prompt window asks for user s name while the second asks for the user s student id. The student id would be printed on the html document while the greeting message appears in the alert window. (c): investigate the use of parseint or parsefloat functions. (i) Run the following program, and investigate the use of the function parsefloat. <head> <title> Third example </title> function maximum (x,y) { return Math.max(x,y); var input1 = window.prompt("enter a number: ", 0); var input2 = window.prompt("enter another number: ", 0); var value1 = parsefloat(input1); var value2 = parsefloat(input2); var maxvalue = maximum(value1, value2); var add1 = input1 + input2; var add2 = value1 + value2; document.writeln("<h1> First number: " + value1 + "</h1>"); document.writeln("<h1> Second number: " + value2 + "</h1>"); document.writeln("<h1> maximum: " + maxvalue + "</h1>"); document.writeln("<h1> add1: " + add1 + "</h1>"); document.writeln("<h1> add2: " + add2 + "</h1>");

<head> <body></body> </html> (ii) Modify the example in (i) to prompt user to input three numbers. The first two numbers should be concatenated into one single number. A new function sum(x,y) is then used to calculate the sum of this concatenated number and the third input number. The two numbers and the sum should be printed on three separated lines. As an example, the user has inputted three numbers as 1, 2, and 3. The first number and the second number are concatenated to form 12. This is added to 3 to give a sum of 15. These numbers are then displayed as follows. (d): Control structures The following table summarizes syntax for a few control structures in JavaScript. Decision Structure Syntax Example if if (condition) if (a > b) min=b if/else if (condition) else if (a > b) min=b else min=a while while (condition) do-while do { while (condition) for for (initialization; condition; increment) { switch switch(choice) { case 1 : statements; break; i=0; while (i<10) i++; i=0; do { i++ while (i<10) for (i=0;i<10;i++) a=i*i;

case 2 : statements; break; default: statements; (i) The following code shows an example of calculating the sum of an input integer n by using the switch statement. The integer n must be greater than 0, but cannot be larger than 3. <head> <title> Fourth example </title> var input = window.prompt("enter a number (1-3) : ", 0); var value = parsefloat(input); var sum = 0; if ((value < 0) (value > 3)) { window.alert ("The number is out of range!"); else { switch (value) { case 3: sum += 3; case 2: sum += 2; case 1: sum += 1; document.writeln("result: " + sum); </head> <body> </body> </html> Modify the above codes so that user is allowed to input the number between 1 and 5. You should still use the switch statement. (ii) When the range is getting large, the number of cases in the switch statement will increase. A for-loop can be used to replace the switch statement. Modify the code in (i) using the for-loop so that user is allowed to input a number between 1 and 45. (iii) Modify (ii) so that if the user inputs an out-of-range number, the user is allowed to input the number again until the number is within the range by using a do-while loop.