Midterm preparation guide

advertisement

Programming games: Preparation guide for midterm.

Re-read the lecture notes.

1.

Define the programming concepts: variable, function, and array. Describe uses in the class projects.

2.

Describe the use of the different bracketing symbols in HTML/JavaScript: ( and ), { and }, [ and ], and < and >.

3.

Define the programming terms: event and event handling. Describe examples in the class projects.

4.

Describe what is meant by datatype. List at least 3 datatypes.

5.

What is the representation in binary of the (decimal) numbers: 5, 2015? What is the representation in decimal of the binary numbers: 1010, 1111110?

6.

What is the representation in hexadecimal of the (decimal) numbers: 5, 55, 164, 255, 1011?

Describe using colors what would be the color of #CC0022, #00FFCF.

7.

Given that the ASCII representation for A is 01000001 and B is 01000010, then write how the string ABAA would appear in memory.

8.

Describe what is meant by application state. You can use the dice game or the virtual dog.

9.

Describe the rules of a dice game containing the following code: if (firstthrow) {

switch (sum) {

case 2: case 12:

alert("You win.");

break:

case 7: case 8:

alert("You lose.");

break;

default:

firstthrow = false;

pointvalue = sum;

}}

else {

if (sum>pointvalue) {

alert("You win.");

firstthrow = true;

}

else if (sum<pointvalue) {

alert("You lose.");

firstthrow = true;

}

}

10.

Write the HTML for an image tag named "pet" holding an image file named "cat.jpg"

Write a javascript function called change that will make the image in that image element be

.

"dog.jpg" .

11.

Write the code to make a call to the function move() every 200 milliseconds. (Hint: this is a single line.) How many times/second is this? What would the number be for once every 3 seconds?

12.

Write the HTML5 JavaScript for drawing a blue rectangle outline 100 pixels wide, 40 pixels tall, at the left side of the canvas, in the middle vertically (canvas is 600 by 400 pixels).

Assume the variable ctx holds the context.

13.

What do the following statements produce (assume ctx has been set to be a canvas context)? Make a sketch, assuming a canvas 600 by 400 pixels. Describe the colors.

ctx.fillStyle ="purple": ctx.fillRect(10,10,200,400); ctx.strokeStyle = "rgb(0,100,0)"; ctx.strokeRect(100,50,50,50);

14.

Describe the effect of putting a var statement (for example, var total;

) inside a function definition versus outside a function definition.

15.

What is wrong with the following code fragment for reporting the days in the month indicated by the variable mon ? There are 4 things! For each problem, is it a syntactic error

(meaning badly formed code) or a semantic error (error of meaning)? switch [mon){ case "Sep": case "Apr": case "Jun": case "Dec":

numOfDays = 30; case "Feb":

numOfDays = 28;

default:

numOfDays = 31;

}

16.

Write a function that draws an image held in an Image variable named flower on the canvas at the position x and y .

17.

Describe what the following code does. if (income > expenses) {

mood = "happy";}

else {

mood = "miserable";}

18.

Write the code for a form that has a submit button with label "Enter", and 2 input fields of type text. Put the words First Name and Last Name before each of the two input fields. Make the action on hitting the submit button to be

"return enternames();"

19.

Describe three ways to specify color for fill and stroke when drawing on canvas and give the commands. Assume the variable ctx holds the canvas context.

20.

Describe the use of a single = sign versus two equal signs:

== and versus three equal signs: === .

21.

What do each of these operators do:

||,==,!=.

+, -,*, /, %, the combination of ? and :, &&,

22.

Write the condition that checks if a number held in the variable less than 5. total is greater than 10 or

23.

Trick question: what is the value of the variable a = “12”; c after these 3 statements: b = “30”; c = a + b;

24.

Write the JavaScript for a for-loop that adds up the values in an array named grades .

25.

Write the code in HTML5 JavaScript to draw a smiley face: a circle and an arc inside the circle. The drawing will consist of two arcs: one a complete circle and the other less than a semicircle.

26.

What does the following JavaScript statement do canvas1.addEventListener(“mouseover”,change, false);

27.

28.

Describe the new semantic elements in HTML5? What are benefits from using them.

Describe the use of the semanatic element article in the Favorite Sites assignment.

29.

Using a <button> element, write the HTML to invoke a function named toss (no parameters) when the player clicks on the button. Make the button display the word TOSS.

30.

Write the code to set up a call to the function named toss (no paremeters) when the player clicks the mouse on the canvas. Assume the canvas has been defined in the body with id=”canvas” and the variable canvas1 has been set: canvas1 = document.getElementById(“canvas”);

Hint: this is one line (one statement).

Download