JavaScript Exercise

Question 1 

1. JavaScript and Java are really just two slightly different names for the same language.

 True 

 False 

1 points

 

Question 2 

1. Scripting languages are commonly used with video game engines to ease the development of game features that may need to be "fine-tuned" (such as in-game character behavior, item locations, etc.) while the main game-engine is in development or even after the game has been completed and shipped.

 True 

 False 

1 points

 

Question 3 

1. Like Java, JavaScript requires that all variables be declared and assigned a "type" before their first use.

 True 

 False 

1 points 

 

Question 4 

1. Scripting languages were originally developed to help tie ("glue") together the functionally of multiple independent programs developed in systems languages.

 True 

 False 

1 points

 

Question 5 

1. Statically typed Systems Languages are generally able catch certain types of programming errors (which scripting languages cannot) before the program is ever even run.

 True 

 False 

1 points  

 

Question 6 

1. Due to their superior speed and maintainability, Scripting Languages are generally considered superior to Systems Languages for large-scale application development involving vast amounts of code and many active developers.

 True 

 False 

1 points 

 

Question 7 

1. Though the Java Programming language is not a scripting language itself, there are other languages which utilize the Java Virtual Machine and Java Platform which are considered true scripting languages.

 True 

 False 

1 points 

 

Question 8 

1. JavaScript is limited in the sense that it is only useful within "web pages"; as JavaScript is not useful for "server-side" applications or client applications outside of a web browser.

 True 

 False 

1 points

 

Question 9 

1. In JavaScript, one function can be defined inside of another function's definition.

 True 

 False 

1 points 

 

Question 10 

1. When numeric user input is assigned to a variable (from a field or dialog box), it is returned to JavaScript as an object of type String.

 True 

 False 

1 points  

 

Question 11 

1. Most "modern" Scripting Languages offer some form of Object-Oriented Programming capabilities.

 True 

 False 

1 points 

 

Question 12 

1. In JavaScript, a function declared with three input parameters, must always receive exactly three parameters to avoid an error condition.

 True 

 False 

1 points  

 

Question 13 

1. Unlike Java methods, JavaScript functions may accept other functions as parameters and return new functions as results.

 True 

 False 

1 points 

 

Question 14 

1. Syntax errors in a JavaScript program (on a web page) may go undetected since the browser never explicitly reports such errors directly to the user.

 True 

 False 

1 points  

 

Question 15 

1. A key difference between "Statically Typed" languages (like Java) and "Dynamically Typed" languages (like JavaScript) is the following: In Statically typed languages, the "type information" is associated with identifiers whereas in Dynamically typed languages, the type information is associated with values.

 True 

 False 

1 points 

 

Question 16 

1. JavaScript is an example of what we commonly call a "Statically Typed" Language.

 True 

 False 

1 points  

 

Question 17 

1. ECMAScript defines the standards and related syntax for the programming language commonly known as JavaScript.

 True 

 False 

1 points  

 

Question 18 

1. Like Java and C++, JavaScript uses "case sensitive" identifiers.

 True 

 False 

1 points

 

Question 19 

1. In JavaScript, the following function may return either a Numeric value or a String simply based on the type of data passed to it as parameters.

 

function f(a,b) { return a + b };

 True 

 False 

1 points 

 

Question 20 

1. In JavaScript, every statement must end with a Semicolon, or a syntax error will result.

 True 

 False 

1 points 

 

Question 21 

1. Given the proper parameters to fun, the following would be syntactically legal in JavaScript...

 

   function fun(x,y) { 

       if (y < 2) return 1; 

       return x(x,y-1) * y; 

    } 

 True 

 False 

1 points  

 

Question 22 

1. In JavaScript's syntax, the keyword "function" may be used to declare a new class from which new objects will be created as well as declaring simple functions which may be invoked directly.

 True 

 False 

1 points  

 

Question 23 

1. Most scripting languages generally fall into the category of:

  Query Lanuages

  Assembly Languages

  Low-Level Languages

  High-Level Languges

1 points  

 

Question 24 

1. What company first developed JavaScript

  IBM

  JavaSoft

  Netscape

  Oracle Corporation

  Sun Microsystems

1 points 

 

Question 25 

1. Which of the following utilizes the proper syntax for an "alert box"

  alert = new "Hello World"

  alert(This is a test)

  alert("This is a test")

  alertBox("This is a test")

1 points 

 

Question 26 

1. In Javascript, the statement 

var z = 4 + "2"; 

 

would result in z having a value of: 

  "4 + 2"

  "6"

  "42"

  It would produce a syntax error due to the type mismatch.

1 points  

 

Question 27 

1. What is the output of the following fragment

function f(x,y) {

    return (x(y)*4)

}

var z = function(x) {return x*2};

 

alert (f(z, 3));

  24

  4

  12

  2

1 points

 

Question 28 

1. The code fragments below all represent attempts to declare/define a new function called myFunction which accepts two numbers and multiplies them.  Select all of versions of the code which may used to declare and define the new function.  (Hint, a choice being "syntactically valid", doesn't mean that it actually declares a new function usable as described.)

  myFunction (x,y) { 

     return x*y; 

  new myFunction (x,y) { 

     return x*y; 

  var myFunction = function(x,y) { 

    return x*y; 

}  

  var myFunction = new function(x,y) { 

    return x*y; 

}

2 points

 

Question 29 

1. Aside from JavaScript, which of the following is also considered a "Scripting Language".

  TCL

  C++

  Assembly Language

  Java

1 points   

 

Question 30 

1. Which is the correct function in JavaScript to execute another function called show() after a 5 second delay.

  setTimeout(show(), 5000);

  setTimeout("show()", 5);

  setTimeout(show, 5000);

  wait(5);

show();

1 points 

 

Question 31 

1. (NOTE: You may need to test the following behavior for yourself.)

If the user presses the "cancel" button when the following code is run

var response = prompt("Enter data");

alert(response.length);

The result would be:

  "null" will be displayed.

  "0" will be displayed.

  An empty string will be displayed.

  An "exception" because result is null.

1 points

 

Question 32 

1. In JavaScript, a function is declared to expect three parameters, but is only passed two parameters as follows:

function f(a,b,c) { return a + b + c }

var r = f(5,6)

 

What is the actual result and --specifically -- why?

2 points   

 

Question 33 

1. In JavaScript, a function is declared to expect three parameters, but is passed four parameters as follows:

function f(a,b,c) { return a + b + c }

var r = f(1,2,3,4)

What is the actual result and -- specifically -- why?

2 points

 

Question 34 

1. What is displayed by the statement: alert(00123)? Why is this the case?

1 points  

 

Question 35 

1. Write a JavaScript function called stringRepeat(theString, theDelimiter, repetitions) that accepts three parameters as follows:

• An arbitrary string value.

• A string to act as a separator (see below).

• the number of times the string should be repeated. 

• (For simplicity, you can assume it's an integer.. i.e, no decimal point)

The function should return a new string as illustrated below.

NOTE:  This function should not display any results itself, but only return the proper string.

For example:

A call to stringRepeat("hello", "_", 3) would return:  hello_hello_hello

A call to stringRepeat("x", ",", 5) would return:   x,x,x,x,x

A call to stringRepeat("Y", "", 2) would return:   YY

 

NOTE: You only need to show the function itself... not a complete web page.

5 points 

 

Question 36 

1. Notes:

• You may wish to reuse one of your previous submissions or in-class examples -- with the appropriate modification -- for this question.

• Full full credit, the code/page must properly create and use a JavaScript "object" . 

• Partial credit will be awarded for a solution which (outwardly) functions correctly, but does not utilize objects.

 

Write a simple HTML/JavaScript program which is capable of computing the area of a Circle as follows:

3. On an HTML page, display five (5) elements: 

a. An "input field" where a human can enter the Radius of the Circle. 

a. (This should be labeled on the page as: "Enter Radius:") 

  

b. An "Output Field" (or just a simple HTML "span"; it doesn't matter which) where the output will be displayed. 

• (This should be labeled on the page as: "Calculated Area:")

  

c. A "Button" labeled "Create Object". Clicking this button should: 

• Define a JavaScript Function/Object in code which represents a Circle. (See "2" below)

• NOTE:  Partial credit will be awarded if the solution generates the correct output, but does not actually create an "object". 

 

d. A "Button" labeled "Show Area". Clicking this button should: 

• Call a getArea() method of your Circle object as created above. (See "2" below)

• Display the returned area value in the output field.

 

For Example:

 

4. In a the SAME HTML file create a function/object called Circle(radius) which: 

 .   Accepts the radius value as an initial parameter.

a.   Implements a getArea() function as described above which performs the appropriate calculation and updates the page as described above. 

• (This is the function that should be called when when the user clicks the "Show Area" button described above.)

• Reminder: The area of Circle is:  

    

5. ZIP your file and attach it to this question response.

 

 

Need a custom answer at your budget?

This assignment has been answered 6 times in private sessions.

© 2024 Codify Tutor. All rights reserved