Introduction to Coding

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If I wanted to draw square/rectangle that was forty pixels wide and sixty pixels tall, at 350 to the left and 6 down, what would I code?

rect(350, 6, 40, 60);

If I wanted to assign the variable xPos a value of 10, what would I code?

var xPos = 10;

var w = 10; var h = 50; rect(200, 200, w, h); I want to make h dependent on w, so that if I ever change the value of w, the value of h will change proportionately, so that h is always 5 times as large as w. What expression should h hold?

w * 5

How do you code Winston?

***VERY IMPORTANT*** getImage("creatures/Winston");

var i = 0; while (i < 3) { println(i); i++; } What does the code output?

0 1 2

var xPos = 55; rect(10, 20, 30, 40); ellipse(xPos, 20, 15, 30); ellipse(xPos, 10, 20, 30); At what x position are the ellipses drawn?

55 pixels to the left.

var xPos = 10; var yPos = 5; rect(xPos, yPos, 10, 10); At what x position is the rectangle drawn?

10 pixels to the left.

var width1 = 12; var width2 = 2 * width1 + 5; rect(50, 50, width1, 10); rect(50, 80, width2, 10); If we change the initial value of width1 to 6, what will be the numeric value of the expression stored in width2?

17

var rectWidth = 20; rect(10, 10, rectWidth, rectWidth); How wide is the rectangle?

20 pixels wide.

var i = 3; while (i < 6) { println(i); i += 1; } What does the code output?

3 4 5

var a = 25; var b = a / 5; var c = b + 30; println(b + c); What will the above program print?

40

After running the code: var x = 5; what is the value of x?

5

var x = 3; var i = 0; while (i < 3) { x += 1; i += 1; } println(x); What does the code output?

6

var w = 20; var h = 15; rect(10, 10, w, h); ellipse(10, 10, w, h); How tall is each one of the shapes?

Each of the shapes is 15 pixels tall.

How do I make a single line comment? A multi line comment?

For a single line: //this is my comment For multi line: /* Roses are red Violets are blue I love Winston And Winston loves you*/

var i = 0; while (i < 0) { println("hi"); } What does the code output?

It won't output anything.

How do I concatenate the variables: var myGreeting = "Hey there"; var myName = "Winston"; with a comma and exclamation point?

Make a new variable and declare it with all variables and punctuation, shown below: var sayHello = myGreeting + "," + myName + "!";

If a variable is assigned a value at the beginning of the code, and then again in the middle, which value would the variable take?

The value assigned last.

Can you pass a variable into a text command?

Yes. For example, the code: var myGreeting = "Hello World"; text(myGreeting, 100, 350); would code Hello World at 100 pixels from the right and 350 pixels down on the canvas.

Are variables case-sensitive?

Yes. For example, xPos is different than xpos.

var big = 100; var small = 10; rect(100, 100, big, big); rect(100, 100, small, small); We want to make small dependent upon big, so that they keep the same proportion when we change them - small should always be 1/10 the size of big. What expression should small store?

big / 10

var bodySize = 100; var faceSize = 50; ellipse(200, 200, bodySize, bodySize); ellipse(200, 150, faceSize, faceSize); If we want to make faceSize dependent on bodySize, so that faceSize is always one-half bodySize, what expression should the faceSize variable store instead?

bodySize / 2

If I wanted to draw an circle/oval that was thirty pixels wide and thirty pixels tall, at 100 to the left and 200 pixels down, what would I code?

ellipse(100, 200, 30, 30);

var i = 0; while (i < 3) { println("hi"); i++; } What does the code output?

hi hi hi

var i = 0; while (i < 3) { println("hi"); i++; } println("bye"); What does the code output?

hi hi hi bye

var scoop1 = 40; var scoop2 = 30; triangle(200, 250, 180, 200, 220, 200); ellipse(200, 180, scoop1, scoop1); ellipse(200, 145, scoop2, scoop2); If we want to make scoop2 dependent on scoop1, so that scoop2 is always 10 pixels smaller than scoop1, what expression should we store in the scoop2 variable?

scoop1 - 10

If I wanted to type Hello World! on my canvas, and place it at 100 pixels from the right and 350 pixels down, what would I code?

text("Hello World", 100, 350);


Kaugnay na mga set ng pag-aaral

Chapter 69: Management of Patients With Neurologic Infections, Autoimmune Disorders, and Neuropathies 2

View Set

Neurosensory and Musculoskeletal

View Set

ExamFX Life Insurance (Taxes, Retirement, and Other Insurance Concepts)

View Set

AR Life Insurance Exam Study Guide

View Set