Javascript Arrays Ch.19
Array definition & for loop var quiz = [85,90,100,0]; // creates an array var ex = []; ex[0] = 89; // add the quiz grades quizTotal = 0; for( int i=0; i< quiz.length; i++) quizTotal= quizTotal + quiz[i]; quizTotal = quizTotal – quiz.min();
If else var points= 87; if points >= 90 grade = “A”; else if points>=85 grade = “A-”
Function definition Write a function that generates two random numbers between 0-10 and adds them and returns them. function addTwo() { var num1 = Math.random()*10; var num2 = Math.random()*10; var sum = num1 + num2; return sum; }
Function call A function has to be called in order to be activated. var total = addTwo();
One more function Write a function that rolls a pair of dice: if the sum > 10 return 1 Else returns 0;
Summary We studied If..else For.. Loop Function Random function