JavaScript | 자바스크립트 | FUNCTIONS 둘
JavaScript | 자바스크립트 | FUNCTIONS 둘
Two. Functions and Return
File1 _ script.js
var orangeCost = function (price) {console.log(price*5);
};
orangeCost(5);
7/13 Return keyword
File1 _ script.js
// Parameter is a number, and we do math with that parameter
var timesTwo = function(number) {
return number * 2;
};
// Call timesTwo here!
var newNumber = timesTwo(5);
console.log(newNumber);
8/13 Functions, return and if / else
File1 _ script.js
// Define quarter here.
var quarter = function (number) {
return number/4;
};
if (quarter(12) % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}
Three. Functions and Variables
9/13 Functions with two parameters
File1 _ script.js
// Write your function starting on line 3
var perimeterBox = function (length, width) {
return length + length + width + width;
};
perimeterBox(3,4);
10/13 Global vs Local Variables
File1 _ script.js
var my_number = 7; //this has global scope
var timesTwo = function(number) {
var my_number = number * 2;
console.log("Inside the function my_number is: ");
console.log(my_number);
};
timesTwo(7);
console.log("Outside the function my_number is: ")
console.log(my_number);
| scope... is hard to understand. | scope... 조금 어렵군요.
11/13 Functions recap
File1 _ script.js
var nameString = function (name) {
return "Hi, I am" + " " + name;
};
console.log(nameString("JONE STUDIO"));
12/13 Functions & if / else
File1 _ script.js
var sleepCheck = function (numHours) {
if (numHours >= 8) {
return "You're getting plenty of sleep! Maybe even too much!";
} else {
return "Get some more shut eye!";
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));
| comparison operators
> Greater than
< Less than
<= Less than or equal to
>= Greater than or equal to
=== Equal to
!== Not equal to
13/13 Conclusion
File1 _ script.js
Next Course: Build "Rock, Paper, Scissors"
