Get All Week Introduction to Computer Programming Quiz Answers
Table of Contents
Introduction to Computer Programming Week 01 Quiz Answers
Quiz 1: Getting started with P5.js
Q1. JavaScript is a…?
Q2. P5.js is a…?
ViewQ3. Where is JavaScript predominately used?
ViewQ4. In programming what is a command?
ViewQ5. In programming, what is a library?
View.
Q6. Select all the answers you think are correct.
P5.js has commands for…?
Hint: Use the P5.js reference page to help you.
View2.interacting and manipulating the webpages DOM
3.user interaction with the mouse and keyboard
4.text and typography
5.loading a displaying images
6.drawing primitive shapes
Quiz 2: 2D coordinate system
Q1. What is the P5.js command for a new canvas?
ViewQ2. What is a pixel?
ViewQ3. The coordinates (0,0) represent which corner of the canvas?
ViewQ4. The x coordinate represents the number of pixels:
ViewQ5. The y coordinate represents the number of pixels:
ViewQ6. In a coordinate pair, such as (400,300), which coordinate is first?
ViewQ7. Which coordinate system is used by the canvas?
ViewQ8.How will the following rectangle be drawn to the canvas?
rect(100, 200, 150, 300);
Introduction to Computer Programming Week 02 Quiz Answers
Quiz 1: RGB colours
Q1. What color does the following RGB color value represent?
(255,255,255)
ViewQ2. In RGB colors if all 3 values are the same what do we know for definite about the color?
ViewQ3. What color is represented by the following RGB value?
View(255,255,0)
Q4. What color is represented by the following RGB value?
(0,256,256)
ViewQ5. What color is represented by the following RGB value?
(140, 0, 255)
Hint: You might want to use an online color picker to help you.
ViewQ6. What RGB value represents the following color?
ViewQ7. An RGB color value takes 24 bits of computer memory, 8 bits (or one byte) for red green, and blue. How many colors does this mean we can store overall?
ViewQ8. How many possible values are there for one byte of information?
ViewQuiz 2: setup, draw, and Programme Flow
Q1. When is the setup() function called?
ViewQ2. When is the draw() function called?
ViewQ3. Where would you normally call createCanvas()?
ViewQ4. Look at the following code carefully. What do you expect to see drawn to the screen when the application runs?
12345678910111213
function setup()
{
createCanvas(500, 500);
}
function draw()
{
fill(255, 0, 0);
rect(100, 100, 200, 200);
ViewQ5. Look at the following code carefully. What do you expect to see drawn to the screen when the application runs?
function setup()
{
createCanvas(500, 500);
}
function draw()
{
fill(255, 0, 0, 255);
rect(100, 100, 200, 200);
fill(0, 0, 255, 100);
ViewQ6. Look at the following code carefully. What do you expect to be drawn to the screen when it runs?
function setup()
{
createCanvas(500, 500);
}function draw()
{
fill(0, 0, 255);
rect(100, 100, 300, 300);
ViewQ7. Consider the following code carefully. What is displayed to the screen when the program is run?
function setup()
{
createCanvas(500, 500);
}
function draw()
{
fill(0, 0, 255);
rect(100, 100, 300, 300);
ViewHint: imagine the program has been running for a few seconds and base your judgment on draw having been run several times.
Q8. Consider the following code carefully. What is displayed to the screen when the program is run?
function setup()
{
createCanvas(500, 500);
}
function draw()
{
noStroke();
fill(255, 0, 0, 255);
rect(100, 100, 200, 200);
ViewHint: If there is some code you don’t recognise. Do not forget you can look it up in the p5.js reference.
Quiz 3: ellipse, rectangle, line, triangle, point
Q1. How many arguments does the point() function take?
Hint: Arguments are the numbers in brackets at the end of the function call separated by commas.
ViewQ2. Which of the following commands draw the line in the picture below? Two of the answers below are correct, select them both.
Hint: Don’t worry about the precise coordinates try and work out the rough direction of the line.
Viewline(100,320,80,250);
Q3. Which of the following commands drew the shape in the picture below?
ViewQ4. Which of the following commands turns the shape green?
ViewQ5. Which of the following commands draws a square to the screen?
ViewQ6. Do the following two triangle commands draw the same triangle or a different triangle?
12
triangle(100,100,150,50,200,100);
triangle(150,50,200,100,100,100);
Q7. The code below draws the triangle as shown in the first image. what is the smallest number of arguments used in the triangle function call do you need to change to draw the triangle in the second image?
123456789
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
fill(200,0,0);
triangle(100,100,150,50,200,100);
}
first image:
second image:
Hint: The bases of the triangles are the same.
ViewQ8. Which of the following shapes can you not draw with a single P5.js command?
ViewQuiz 4: Using the console and debugging syntax errors
Q1. Where do you find the console?
ViewQ2. Look at the following error. Where is the error in the code?
ViewQ3. What kind of error or error is included in the following code?
123456789
function setup()
{
createCanvas(500, 500);
}
function draw()
{
triangle(100, 100, 150, 100);
}
Q4. What kind of error is included in the following code?
123456789
function setup()
{
createcanvas(500, 500);
}
function draw()
{
rect(100, 100, 150, 100);
}
Q5. What kind of error is included in the following code?
123456789
function setup()
{
createCanvas(500, 500);
}
function draw()
{
rect(100, 100, 150, 100);
Introduction to Computer Programming Week 03 Quiz Answers
Quiz 1: Built-in Variables: mouseX, mouseY, and Events
Q1. Which of the following variables represents the mouse’s Y coordinate?
ViewQ2. Which of the following statements best represents what a variable is?
ViewQ3. Study the following code carefully. What is visible on the canvas when the program executes?
1234567891011
function setup()
{
createCanvas(500, 500);
}
function draw()
{
fill(0, 0, 220);
rect(100, 100, 300, 300);
background(0, 0, 0);
Q4. What is displayed on the screen when the following code is executed?
12345678910111213
function setup()
{
createCanvas(500, 500);
}
function draw()
{
background(0, 0, 0);
fill(220, 0, 220);
noStroke();
Q5. What does the following code draw to the screen?
12345678910111213
function setup()
{
createCanvas(500, 500);
}
function draw()
{
background(0, 0, 0);
noStroke();
fill(220, 0, 220);
Q6. What does the following code draw to the screen?
12345678910111213
function setup()
{
createCanvas(500, 500);
}
function draw()
{
background(0, 0, 0);
noStroke();
fill(220, 0, 220);
Q7. What value is stored in mouseX?
ViewQ8. When is the keyPressed() function called?
ViewQ9. When is the mousePressed() function called?
Hint: You may want to read the p5.js documentation.
ViewQ10. What colour is the ellipse drawn in the following code after the mouse has been pressed and released?
12345678910111213141516
function setup()
{
createCanvas(500, 500);
}
function draw()
{
fill(255, 0, 0);
rect(100, 100, 300, 300);
Quiz 2: Create your own variables: var, initialising and assigning
Q1. A variable name cannot start with…?
ViewQ2. Which of the following variables are valid names? (Three are correct.)
ViewQ3. Formally, creating a variable is called?
View declaringQ4. Formally, assigning a variable its first value is called?
ViewQ5. What does a equal at the end of executing the following code?
1234
var a = 3;
var b = 23;
var c = b;
a = c;
Q6. What does the variable ‘a’ equal at the end of the setup() function in the code snippet below?
1234567
var a = 0;
function setup()
{
createCanvas(400, 200);
a = width;
}
Q7. What does the variable ‘a’ equal at the end of the setup() function in the code snippet below?
1234567
var a = 0;
function setup()
{
createCanvas(400, 200);
a(height);
}
Q8. True or False: JavaScript variables can be created without the var keyword?
ViewQuiz 3: Working with operators
Q1. What does the variable equal at the end of this code snippet?
Try and complete these questions without using a calculator!
1
var a = 10+15;
Q2. What does the variable equal at the end of this code snippet?
Try and complete these questions without using a calculator!
1
var a = 18/3;
Q3. What does the variable a equal at the end of this code snippet?
Try and complete these questions without using a calculator!
1
var a = 1010+13;
Q4. What does the variable a equal at the end of this code snippet?
Try and complete these questions without using a calculator!
1
var a = 10+100/(5+5);
Q5. What does the variable equal at the end of this code snippet?
Try and complete these questions without using a calculator!
12
var b = 20;
var a = b*20+20/5;
Q6. What does the variable equal at the end of this code snippet?
Try and complete these questions without using a calculator!
12
var b = -20;
var a = 20-b;
Q7. What does the variable equal at the end of this code snippet?
Try and complete these questions without using a calculator!
12
var a = 3;
a = a+5*2
Q8. Look at the following code carefully. How is the ellipse animated across the canvas?
123456789101112131415
var a = 0;
function setup()
{
createCanvas(500, 500);
}
function draw()
{
background(200);
Quiz 4: Inspecting Variables in the Console
Q1. Which 2 of the following commands will write text to the console? (The others will cause an error.)
Viewconsole.log(‘hello console’);
Q2. What arithmetic operator replaces ??? in the following console.log() command to correctly display the message in the console?
12
var x = 42;
console.log(“the value of x is ” ??? x);
1 point
Q3. What is printed to the console during the execution of the following program?
12345678910111213141516
var a = 0;
function setup()
{
createCanvas(500, 500);
}
function draw()
{
background(200);
Q4. What is printed to the console after executing the following code snippet?
12
var x = 42;
console.log(y);
Get All Course Quiz Answers of IBM Technical Support Professional Certificate
Introduction to Hardware and Operating Systems Quiz Answers
Introduction to Software, Programming, and Databases Quiz Answers
Introduction to Networking and Storage Quiz Answers
Introduction to Cybersecurity Essentials Quiz Answers
Introduction to Cloud Computing Coursera Quiz Answers
Introduction to Technical Support Coursera Quiz Answers