Programming games: Preparation guide for midterm
- Re-read lecture notes (HTML/JavaScript).
- Define the programming concepts: variable, function, and array. Describe uses in the class projects.
- Describe the use of the different bracketing symbols in HTML/JavaScript: ( and ), { and }, [ and ], and < and >.
- Define the programming terms: event and event handling. Describe examples in the class projects.
- Describe what is meant by datatype. List at least 3 datatypes.
- What is the representation in binary of the (decimal) numbers: 5, 55, 164, 2011? What is the representation in decimal of the binary numbers: 1010, 1111110?
- 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.
- Given that the ASCII representation for A is 01000001 and B is 01000010, then write how the string ABAA would appear in memory.
9. Assume that current Balance is $100, newPurchases is $200, annualInterest is 24%, and payment is $100. What is the value of Balance after this code:
Balance = Balance + newPurchases – payment;
if (Balance>0) {
Balance = Balance + Balance * (annualInterest/12); }
- Describe using a JavaScript expression and in words what is meant by compound interest.
- Describe what is meant by application state. You can use the dice game or the virtual dog.
- Describe the rules of a dice game containing the following code:
if (firstthrow) {
switch (sum) {
case 10: case 11: case 12:
alert("You win.");
break:
case 2: case 3:
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;
}
}
- Write the HTML for an image tag named "pet" holding an image file named "cat.jpg". Write a javascript function that will make the image in that image tag be "dog.jpg".
- 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?
- 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.
- Describe the effect of putting a var statement (for example, var total; ) inside a function definition versus outside a function definition.
- What is wrong with the following code fragment for calculating the days in the month indicated by the variable mon? There are 4 things! For each one, 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;
} - Write a function that draws an image held in an Image variable named flower on the canvas at the position x and y.
- Describe what the following code does.
if (income > expenses) {
mood = "happy";}
else {
mood = "miserable";} - 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();"
- 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.
- Describe the use of a single = sign versus two equal signs: == and versus three equal signs: ===.
23. What do each of these operators do: +, -,*, /, %, the combination of ? and :, &, ||,==,!=.
24. Write the condition that checks if a number held in the variable total is greater than 10 or less than 5.
- Trick question: what is the value of the variable c after these 3 statements:
a = “12”;
b = “30”;
c = a + b; - Write the JavaScript for a for-loop that adds up the values in an array named grades.
- Write the code in HTML5 JavaScript to draw a smiley face: a circle and an arc inside the circle.
- Describe the new semantic elements in HTML5? What are the advantages? What was used in the Favorite Sites assignment?
- 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.
- 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).