CODEHS JAVASCRIPT CONTROL
STRUCTURES :) STUDY QUESTIONS
& ANSWERS
5.1.4 Do You Have a Dog? - ANSWER-function start(){
var dog = true;
println("Do you have a dog?: " + dog);
}
5.2.6 Can You Graduate? - ANSWER-function start(){
var credit = readBoolean("Do you have enough credits? ");
var gradReq = readBoolean("Have you met all of your graduation requirements? ");
var canGrad = credit && gradReq;
println ("Can you graduate? " + canGrad);
}
5.2.7 School's Out - ANSWER-function start(){
var weekday = readBoolean("Is today a weekday? ");
var holiday = readBoolean("Is today a holiday? ");
var noSchoolToday = !weekday || holiday;
println("There is no school today: " + noSchoolToday);
}
5.3.5 Rolling Dice - ANSWER-function start(){
var firstDie = readInt("First die? ");
var secondDie = readInt("Second die? ");
var doubleRoll = firstDie == secondDie;
println("Rolled Doubles? " + doubleRoll);
, }
5.3.6 Girl Scout Designation - ANSWER-function start(){
var cookies = readInt("How many boxes did you sell? ");
var badges = readInt("How many badges do you have? ");
var volunteer = readInt("How many hours have you volunteered? ");
var gold = cookies >= 50 && badges >= 10 && volunteer >= 25 || cookies >= 100;
println("Is gold status? " + gold);
}
5.4.7 Teenagers - ANSWER-function start(){
var age = readInt("What is your age? ");
if(age >= 13 && age <=19){
println("Yes,you are a teenager.");
} else {
println("No,you are not a teenager.");
}
}
5.4.8 Dietary Restrictions - ANSWER-function start(){
var dietRestrictions = readLine("Any dietry restrictions?");
if(dietRestrictions == "lactose intolerant") {
println("No cheese");
} else if(dietRestrictions == "vegetarian") {
println("Veggie burger");
} else {
println("No alterations");
}
}
5.5.4 Chalkboard - ANSWER-function start(){
STRUCTURES :) STUDY QUESTIONS
& ANSWERS
5.1.4 Do You Have a Dog? - ANSWER-function start(){
var dog = true;
println("Do you have a dog?: " + dog);
}
5.2.6 Can You Graduate? - ANSWER-function start(){
var credit = readBoolean("Do you have enough credits? ");
var gradReq = readBoolean("Have you met all of your graduation requirements? ");
var canGrad = credit && gradReq;
println ("Can you graduate? " + canGrad);
}
5.2.7 School's Out - ANSWER-function start(){
var weekday = readBoolean("Is today a weekday? ");
var holiday = readBoolean("Is today a holiday? ");
var noSchoolToday = !weekday || holiday;
println("There is no school today: " + noSchoolToday);
}
5.3.5 Rolling Dice - ANSWER-function start(){
var firstDie = readInt("First die? ");
var secondDie = readInt("Second die? ");
var doubleRoll = firstDie == secondDie;
println("Rolled Doubles? " + doubleRoll);
, }
5.3.6 Girl Scout Designation - ANSWER-function start(){
var cookies = readInt("How many boxes did you sell? ");
var badges = readInt("How many badges do you have? ");
var volunteer = readInt("How many hours have you volunteered? ");
var gold = cookies >= 50 && badges >= 10 && volunteer >= 25 || cookies >= 100;
println("Is gold status? " + gold);
}
5.4.7 Teenagers - ANSWER-function start(){
var age = readInt("What is your age? ");
if(age >= 13 && age <=19){
println("Yes,you are a teenager.");
} else {
println("No,you are not a teenager.");
}
}
5.4.8 Dietary Restrictions - ANSWER-function start(){
var dietRestrictions = readLine("Any dietry restrictions?");
if(dietRestrictions == "lactose intolerant") {
println("No cheese");
} else if(dietRestrictions == "vegetarian") {
println("Veggie burger");
} else {
println("No alterations");
}
}
5.5.4 Chalkboard - ANSWER-function start(){