Download presentation
Presentation is loading. Please wait.
Published byJuliana Roberts Modified over 8 years ago
1
Javascript Arrays Ch.19
2
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();
3
If else var points= 87; if points >= 90 grade = “A”; else if points>=85 grade = “A-”
4
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; }
5
Function call A function has to be called in order to be activated. var total = addTwo();
6
One more function Write a function that rolls a pair of dice: if the sum > 10 return 1 Else returns 0;
7
Summary We studied If..else For.. Loop Function Random function
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.