Programming Test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is printed by the following program? var isRaining = false; var isCloudy = false; var isSunny = !isRaining && !isCloudy; var isSummer = false; var isWarm = isSunny || isSummer; println("Is it warm: " + isWarm);

A

var numApples = 10; var numOranges = 5; if(numApples < 20 || numOranges == numApples){ println("Hello, we are open!"); } else { println("Sorry, we are closed!"); } println("Sincerely, the grocery store");

A

We want to position a Circle circle on our canvas to be at a random position, but we want to keep the entire shape on the screen. Which of the following will accomplish this?

B

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?

B

What is the last thing printed by the following program? var start = 30; var stop = 10; for(var i = start; i >= stop; i-=5){ if(i % 2 == 0){ println(i * 2); } else { println(i); } }

B

What is the output of the following program? var result = 0; var max = 5; for(var i = 0; i < max; i++){ result += i; } println(result);

B

What is the value of the boolean variable canVote at the end of this program? var age = 17; var isCitizen = true; var canVote = age >= 18 && isCitizen;

B

What will be the output of this program? var number = 5; var greater_than_zero = number > 0; if (greater_than_zero){ println(number); }

B

What will the following program print when run? var above16 = true; var hasPermit = true; var passedTest = false; if (above16 && hasPermit && passedTest){ println("Issue Driver's License"); } else { if (above16 || hasPermit || passedTest) { println("Almost eligible for Driver's License"); } else { println("No requirements met."); } }

B

We want to print the phrase "CodeHS is the best" exactly 25 times. What kind of control structure should we use?

D

What will be the output of this program? var number = 5; var greater_than_zero = number > 0; if (greater_than_zero){ if (number > 5){ println(number); } }

D

What will the following program print when run? for (var j = 0; j < 2; j++) { for (var i = 6; i > 4; i--){ println (i); } }

D

What will the following program print when run? var numberOne = 5; var numberTwo = 10; if (numberOne == 5) { println(1); } if (numberOne > 5) { println(2); } if (numberTwo < 5) { println(3); } if (numberOne < numberTwo) { println(4); } if (numberOne != numberTwo) { println(5); }

D

How many times will the following program print "hello"? var i = 0; while(i < 10){ println("hello"); }

D

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem. var SECRET_PASSWORD = "karel"; function start(){ while(true){ var password = readLine("Enter your password: "); if(password == SECRET_PASSWORD){ println("You got it!"); } println("Incorrect password, please try again."); } }

C


Ensembles d'études connexes

World War 1 And Spanish-American War

View Set

Spanisch Encuentros 3 Módulo 1C

View Set

Mental Health: Mostly Personality Disorders NCLEX Questions

View Set

practice exam 3 - missed questions

View Set

Supply Chain Modeling Quiz Exams

View Set

مقرر مدخل اعلام فاينل

View Set