void setup() { Serial.begin(9600); //begin using serial communication } void loop() {int l = 10; //declare a variable called l and give it the value 10int w = 6; //declare a variable called w and give it the value 6int area = l * w; //declare a variable called area and equate it to l times w if(area>50) { Serial.println("The area of the rectangle is big!"); //prints the text if the area is bigger than 50 }else { Serial.println("The area of the rectangle is small"); //prints the text if the area is not bigger than 50 }}
ifelse.mp4
Challenge: Adjust the length and the width in this program to create a false condition
if/else if/else
void setup() { Serial.begin(9600); //begin using serial communication } void loop() {int l = 10; //declare a variable called l and give it the value 10int w = 6; //declare a variable called w and give it the value 6int area = l * w; //declare a variable called area and equate it to l times w if(area<50){Serial.println("The area of the rectangle is small!"); //prints the text if the area is smaller than 50 } else if(area<100){Serial.println("The area of the rectangle is medium"); //prints the text if the previous condition is false} else{Serial.println("The area of the rectangle is huge!"); //prints if the two previous conditions are false}}
ifElseIfElse.mp4
Challenge: Adjust the length or width to create a small or huge rectangle.