I Hate CBT's

View Original

5.2.1 Ghost Answer Key

Question: Stop light

Answer:

Question: Is It Even? Codehs Answers JAVA

var SENTINEL = 0;

function start(){

while(true){

var input = readInt(“Number: “);

if(input == SENTINEL){

println(“DONE!”);

break;

}

if(isEven(input)){

println(“Even”);

}else{

println(“Odd”);

}

}

}

function isEven(x){

return(x % 2 == 0);

}

Answer: Is it even

Question: Ghost

Answer:

Question: Draw

Answer: Draw Something Codehs Answers JAVA

function start(){

var line = new Line(1, 1, 2, 2);

line.setColor([Color.green](https://Color.green));

add(line); var circle = new Circle(30);

circle.setPosition(100, 50);

circle.setColor([Color.blue](https://Color.blue));

add(circle);

var rect = new Rectangle(200, 100);

rect.setPosition(60, 150);

rect.setColor([Color.green](https://Color.green));

add(rect);

}