5.4.5 quadruple with return values CODEHS: FUNCTIONS AND PARAMETERS I WILL UPDATE THIS AS I COMPLETE THEM & GET THEM 100% CONFIRMED 5.1.4: SQUARE function start(){ square(5); square(10); } function square(x){ var squareX = x * x; println(squareX); 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values } ========================= 5.1.5: TRIPLE function start(){ triple(5); triple(10); } function triple(){ var tripleX = 3 * x; 5.4.5 quadruple with return values How to dowload it? 5.4.5 quadruple with return values println(tripleX); } ========================= 5.2.4: AREA OF A TRIANGLE function start(){ triArea(5,10); triArea(10,5); } function triArea(x,y){ 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values var areaX = (1 / 2) * x * y; println(areaX); } ========================= 5.2.5: HEIGHT IN METERS // CONTROL VALUES = CONVERSION FACTORS var INCHES_TO_CM = 2.54; var CM_TO_METERS = 0.01 var FEET_TO_INCHES = 12; // INPUTS HEIGHT -> METERS IN (FEET,INCHES) 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values function start(){ convertHeightToMeters(5,10); convertHeightToMeters(4,2); } // USES CONSTANTS AS CONVERSION FACTORS function convertHeightToMeters(x,y){ var feetToCM = x * FEET_TO_INCHES * INCHES_TO_CM * CM_TO_METERS; var inchesToCM = y * INCHES_TO_CM * CM_TO_METERS; var heightInMeters = feetToCM + inchesToCM; println(heightInMeters); 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values } ========================= 5.3.4: HORIZONTAL LINES function start(){ horizontalLine(100,200); horizontalLine(200,100); horizontalLine(300,50); } function horizontalLine(x,y){ 5.4.5 quadruple with return values How to dowload it? 5.4.5 quadruple with return values var line = new Line(0,x,y,x); add(line); } ========================= 5.3.5: GRAPHICS STOP LIGHT var LIGHT_RADIUS = 35; var STOPLIGHT_WIDTH = 120; var STOPLIGHT_HEIGHT = 350; 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values var BUFFER = 100; var GRAY_COLOR = "#737071"; var centerX = getWidth() / 2; var centerY = getHeight() / 2; function start(){ var rect = new Rectangle(STOPLIGHT_WIDTH, STOPLIGHT_HEIGHT); rect.setPosition(centerX - STOPLIGHT_WIDTH / 2, centerY - STOPLIGHT_HEIGHT / 2); rect.setColor(GRAY_COLOR); add(rect); 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values drawCircle(Color.red, centerY - BUFFER); drawCircle(Color.yellow, centerY); drawCircle(Color.green, centerY + BUFFER); } function drawCircle(color,y){ var circle = new Circle(LIGHT_RADIUS); circle.setPosition(centerX,y); circle.setColor(color); add(circle); 5.4.5 quadruple with return values How to get it? 5.4.5 quadruple with return values } ========================= 5.3.6: POOL TABLE var POOL_BALL_RADIUS = 40; var POOL_BALL_FONT = "30pt Arial"; function start(){ drawPoolBall(Color.orange, 5, 100, 100); 5.4.5 quadruple with return values How to dowload it? 5.4.5 quadruple with return values drawPoolBall(Color.red, 3, 200, 275); drawPoolBall(Color.green, 6, 150, 75); drawPoolBall(Color.black, 8, 75, 300); drawPoolBall(Color.blue, 2, 250, 50); } // DRAWS A POOL BALL function drawPoolBall(color, num, x, y){ var ball = new Circle(POOL_BALL_RADIUS); ball.setColor(color); ball.setPosition(x,y); 5.4.5 quadruple with return values PasteShr 5.4.5 quadruple with return values add(ball); var number = new Text(num); number.setFont(POOL_BALL_FONT); number.setColor(Color.white); number.setPosition(x - (ball.getWidth() / 8), y + (ball.getHeight() / 8)); add(number); } ========================= function start(){ square(5); 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values square(10); } function square(x){ var numSquare = x * x; println(numSquare); return(numSquare); } ========================= 5.4.5: QUADRUPLE WITH RETURN VALUES 5.4.5 quadruple with return values How to get it? 5.4.5 quadruple with return values function start(){ quadruple(5); quadruple(10); } function quadruple(x){ var numQuad = x * 4; println(numQuad); return(numQuad); return(numQuad); 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values } ========================= 5.5.4: IS IT EVEN? var SENTINEL = 0; function start(){ while(true){ var input = readInt("Number: "); if(input == SENTINEL){ println("DONE!"); break; 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values } if(isEven(input)){ println("Even"); }else{ println("Odd"); } } } function isEven(x){ 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values return(x % 2 == 0); } ======================== 5.5.5: MIN function start(){ min(1,2); min(9000,9001); } 5.4.5 quadruple with return values How to dowload it? 5.4.5 quadruple with return values function min(x,y){ if(x < y){ println("MINIMUM VALUE IS: " + x); return(x); }else if(y < x){ println("MINIMUM VALUE IS: " + y); return(y); }else if(x == y){ println("MINIMUM VALUE IS: " + x); return(x); 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values } } ========================= MODULE VI: LOCAL VARIABLES EXAMPLE: // LOCAL VARIABLES ARE CALLED WITHIN A FUNCTION INSTEAD OF CALLING THE VARIABLE FOR THE WHOLE PROGRAM. 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values function start(){ var name = readLine("WHAT IS YOUR NAME? "); println("HELLO, " + name); } ========================= MODULE VII: JAVASCRIPT VS KAREL 5.4.5 quadruple with return values PasteShr 5.4.5 quadruple with return values 5.7.4: MAKE KAREL TURN RIGHT function turnRight(){ karel.rotate(90); if(direction == EAST){ direction == SOUTH; }else if(direction == WEST){ direction == NORTH; }else if(direction == SOUTH){ direction == WEST; }else if(direction == NORTH){ 5.4.5 quadruple with return values How to use it? 5.4.5 quadruple with return values direction == EAST; }else{ println("ERROR: KAREL'S DIRECTION IS NOT PROPERLY SET!"); } } ========================= 5.7.5: MAKING KAREL MOVE ========================= 5.8.1: GHOSTS 5.4.5 quadruple with return values How to get it for free? 5.4.5 quadruple with return values https://ibb.co/pW5PYBM ========================= 5.4.5 quadruple with return values