Section 1

Preview this deck

Inside which HTML element do we put the JavaScript?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (39)

Section 1

(39 cards)

Inside which HTML element do we put the JavaScript?

Front

<script>

Back

How would you write 12345 one digit at a time using HTML & JavaScript?

Front

</title> </head> <body> <script type="TEXT/JAVASCRIPT"> var asNumber = 12345; var asText = asNumber.toString(); document.write("Reading/writing " + asText + " one digit at a time as text: "); var x; for (x=0;x<5;x++) { document.write(asText[x]); } </script> </body> </html>

Back

How do you display line breaks inside popup boxes?

Front

with backslash n Example: alert("Hello
How are you?");

Back

How do you specify a JavaScript block?

Front

{...}

Back

What is JavaScript?

Front

JavaScript is a platform-independent,event-driven, interpreted client-side scripting language.

Back

How would you find the length of a string?

Front

Use the String object .length var txt="Hello Everybody!"; txt.length will return the number of characters in the string "Hello Everybody!"

Back

What are some of the things JavaScript can do to an HTML page?

Front

1. Can react to events(set to execute when a user clicks an element, when the page finishes loading, etc). 2. Can manipulate(read or change) an HTML element. 3. Can validate data(form input). 4. Can detect the visitor's browser(and load another page specifically designed for it). 5. Can create cookies(to store and retrieve information on a visitor's computer).

Back

What are the 3 different kinds of pop-up boxes in JavaScript?

Front

Alert box - users verify that information goes through. To proceed click OK. alert("sometext"); Confirm box - users verify or accept something. To proceed click OK (true) or Cancel (false); confirm("sometext"); Prompt box - users are prompted to input a value to continue. To proceed click OK (input value) or Cancel (null); prompt("sometext","defaultvalue");

Back

What built-in JavaScript values do we know?

Front

Array object - stores multiple values in a single variable. Date object - works with dates and times. String object - manipulates a stored piece of text. Math object - performs mathematical tasks. RegExp (Regular Expression) - used to describe a pattern of characters.

Back

What is a JavaScript variable?

Front

A container to store data.

Back

What is a JavaScript block?

Front

A group of JavaScript statements logically grouped together surrounded by curly braces {...}.

Back

What is the syntax for defining functions?

Front

Function with input arguments (values): <script> function myFunction(arg1, arg2, arg3...) { Some code } </script> ...myFunction(val1, val2, va3....) Function with return value: <script> function myFunction() { Some code Return x; } </script> ...myFunction(val1, val2, va3...)

Back

How do you write "Hello World" in a confirm box?

Front

confirm("Hello World")

Back

Can you pass (a, b, c, d, e, f) into a function as one value? How?

Front

Yes. Use the Array object. var myArray = Array(a,b,c,d,e,f);

Back

How do you write "Hello World" in an alert box?

Front

alert("Hello World")

Back

What should appear at the very end of your JavaScript?

Front

The </script LANGUAGE="JavaScript"> tag

Back

What is the correct syntax for referring to an external script called "xxx.js"?

Front

<script type="text/javascript" src="xxx.js">

Back

How do you declare a variable?

Front

* Declares empty (no value) variable named 'd': var d * Declares variable and assign a value to it. var dat = 1; Assign text value in quotes, var car12 = "Honda"; numeric value - no quotes. * Declares unchangeable (const) variable with value: const d = 32

Back

How can you find a client's browser name?

Front

navigator.appName

Back

How about 2+5+"8"?

Front

78

Back

What is Object Oriented Programming?

Front

A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. OOP is a technique that allows a programmer to reuse and simplify the code.

Back

Where can we place JavaScript in an HTML file?

Front

Either the head or body

Back

How would you find today's date in JS code? Just the year only? Time?

Front

Use the Date object. currDate = new Date(); currYear = currDate.getYear()+1900; currTime = currDate.getTime();

Back

How to read and write a file using JavaScript?

Front

I/O operations like file reading or writing is not possible with client-side JS. But you can code a Java applet that reads files for the script.

Back

Where is JavaScript executed?

Front

On the browser side.

Back

How do you specify comments in JavaScript?

Front

// - Single line comments / ... / - Multi line comments (begin with slash star and end with star slash)

Back

What is a loop? What kinds of JavaScript loops do we know?

Front

A loop is a cycle that repeats same block of code many times. A for loop is used when you know the exact number (of times) you want to run the block. A while loop continues looping through a block of code while a specified condition is true.

Back

Write or modify an existing code so page prompts you to input your name when you press the "Try it" button and has a default value of "Harry Potter". After the input is submitted a greeting appears on the page: "Hello <your name>! How are you today?".

Front

<html> <body> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x; var person=prompt("Please enter your name","Harry Potter"); if (person!=null) { x="Hello " + person + "! How are you today?"; document.getElementById("demo").innerHTML=x; } } </script> </body> </html>

Back

Does the external JavaScript file contain the <script> tag?

Front

No. A JavaScript file contains pure JavaScript, without <script> tags or any other HTML. By convention, files of JavaScript code have names that end with .js.

Back

What is the correct JavaScript syntax to write "Hello World"?

Front

document.write("Hello World")

Back

How do we control a loop?

Front

By specifying: 1) Start/end condition; 2) Number of cycles.

Back

What is a JavaScript function?

Front

A function is a block of JavaScript code that is defined once but may be executed any number of times by an event such as: - clicking a button; - a call within your script; - a call within another function; etc. A function is placed in <head> or <body> section depending when the call is made.

Back

What boolean operators does JavaScript support?

Front

&&, || and !

Back

You should end your lines with what?

Front

;

Back

Can we place function within a function?

Front

Yes. JavaScript function definitions can be nested within other functions, and they have access to any variables that are in scope where they are defined.

Back

Name the JavaScript data types

Front

Number, String, Boolean, Function, Object, Null, Undefined.

Back

How would you make "Hello World" the default text for a prompt box?

Front

prompt("Type 'Hello World' here:","Hello World");

Back

Using LOOP, for the numbers 5 through 35, display: a) every 4th number; b) all numbers less than 12;

Front

<html> <body> <script type="text/javascript"> document.write("<h3>Every 4th number (5-35): </h3>"); for (i=5;i<=35;i=i+4) { document.write("Number: " + i + ";<br>"); } document.write("<h3>All numbers less than 12(5-35): </h3>"); i=5; while (i<12) { document.write("Number: " + i + ";<br>"); i++; } </script> </body> </html>

Back

What does "1"+2+4 evaluate to?

Front

124

Back