Created
April 12, 2016 22:01
-
-
Save anonymous/214f83be50369235bc69a6e3a98a951f to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/moyeho
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/* | |
function yell(myPhrase) { | |
for(var i = 1;i<=10;i++) { | |
if(i==10){ | |
myPhrase = myPhrase.toUpperCase(); | |
} | |
console.log(myPhrase); | |
} | |
} | |
yell('whatever'); | |
*/ | |
/* | |
function daysInMonth(month) { | |
var days = 31; | |
switch(month.toLowerCase()) { | |
case 'april': | |
case 'june': | |
case 'august': | |
case 'november': | |
days = 30; | |
break; | |
case 'february': | |
days = 28; | |
break; | |
} | |
for(var i=1;i<=days;i++) { | |
console.log(month + ' ' + i); | |
} | |
} | |
daysInMonth('March'); | |
*/ | |
// Write a function called average that takes an array //of numbers as a parameter and returns the average of //the array of numbers. | |
/* | |
function average(arr) { | |
var total = 0; | |
for(var i=0;i<arr.length;i++) { | |
total += arr[i]; | |
} | |
// console.log() | |
return total/arr.length; | |
} | |
console.log(average([2,34,54,67,85])); | |
*/ | |
/* | |
Write a function called calculate that takes 3 arguments: num1, num2, and a string representing addition or multiplication ('+' or '*'). Have that function decide which math operation to perform, then call another function for the appropriate operation. For example, calculate(4, 5, '*'); should call another function internally that looks like this multiply(4, 5) and returns the value 20. | |
*/ | |
function calculate(num1, num2, operator) { | |
//console.log(operator); | |
function add(n1,n2) { | |
//console.log("inside add"); | |
return n1 + n2; | |
} | |
function multiply(n1,n2) { | |
//console.log("inside multiply"); | |
return n1 * n2; | |
} | |
if(operator == "+") { | |
//console.log("do add"); | |
return add(num1,num2); | |
} | |
else if(operator == "*") { | |
//console.log("do multiply"); | |
return multiply(num1,num2); | |
} | |
return 0; | |
} | |
console.log(calculate(3,7,"+")); | |
console.log(calculate(3,7,"*")); | |
console.log(calculate(3,7,"-")); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/* | |
function yell(myPhrase) { | |
for(var i = 1;i<=10;i++) { | |
if(i==10){ | |
myPhrase = myPhrase.toUpperCase(); | |
} | |
console.log(myPhrase); | |
} | |
} | |
yell('whatever'); | |
*/ | |
/* | |
function daysInMonth(month) { | |
var days = 31; | |
switch(month.toLowerCase()) { | |
case 'april': | |
case 'june': | |
case 'august': | |
case 'november': | |
days = 30; | |
break; | |
case 'february': | |
days = 28; | |
break; | |
} | |
for(var i=1;i<=days;i++) { | |
console.log(month + ' ' + i); | |
} | |
} | |
daysInMonth('March'); | |
*/ | |
// Write a function called average that takes an array //of numbers as a parameter and returns the average of //the array of numbers. | |
/* | |
function average(arr) { | |
var total = 0; | |
for(var i=0;i<arr.length;i++) { | |
total += arr[i]; | |
} | |
// console.log() | |
return total/arr.length; | |
} | |
console.log(average([2,34,54,67,85])); | |
*/ | |
/* | |
Write a function called calculate that takes 3 arguments: num1, num2, and a string representing addition or multiplication ('+' or '*'). Have that function decide which math operation to perform, then call another function for the appropriate operation. For example, calculate(4, 5, '*'); should call another function internally that looks like this multiply(4, 5) and returns the value 20. | |
*/ | |
function calculate(num1, num2, operator) { | |
//console.log(operator); | |
function add(n1,n2) { | |
//console.log("inside add"); | |
return n1 + n2; | |
} | |
function multiply(n1,n2) { | |
//console.log("inside multiply"); | |
return n1 * n2; | |
} | |
if(operator == "+") { | |
//console.log("do add"); | |
return add(num1,num2); | |
} | |
else if(operator == "*") { | |
//console.log("do multiply"); | |
return multiply(num1,num2); | |
} | |
return 0; | |
} | |
console.log(calculate(3,7,"+")); | |
console.log(calculate(3,7,"*")); | |
console.log(calculate(3,7,"-")); | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
function yell(myPhrase) { | |
for(var i = 1;i<=10;i++) { | |
if(i==10){ | |
myPhrase = myPhrase.toUpperCase(); | |
} | |
console.log(myPhrase); | |
} | |
} | |
yell('whatever'); | |
*/ | |
/* | |
function daysInMonth(month) { | |
var days = 31; | |
switch(month.toLowerCase()) { | |
case 'april': | |
case 'june': | |
case 'august': | |
case 'november': | |
days = 30; | |
break; | |
case 'february': | |
days = 28; | |
break; | |
} | |
for(var i=1;i<=days;i++) { | |
console.log(month + ' ' + i); | |
} | |
} | |
daysInMonth('March'); | |
*/ | |
// Write a function called average that takes an array //of numbers as a parameter and returns the average of //the array of numbers. | |
/* | |
function average(arr) { | |
var total = 0; | |
for(var i=0;i<arr.length;i++) { | |
total += arr[i]; | |
} | |
// console.log() | |
return total/arr.length; | |
} | |
console.log(average([2,34,54,67,85])); | |
*/ | |
/* | |
Write a function called calculate that takes 3 arguments: num1, num2, and a string representing addition or multiplication ('+' or '*'). Have that function decide which math operation to perform, then call another function for the appropriate operation. For example, calculate(4, 5, '*'); should call another function internally that looks like this multiply(4, 5) and returns the value 20. | |
*/ | |
function calculate(num1, num2, operator) { | |
//console.log(operator); | |
function add(n1,n2) { | |
//console.log("inside add"); | |
return n1 + n2; | |
} | |
function multiply(n1,n2) { | |
//console.log("inside multiply"); | |
return n1 * n2; | |
} | |
if(operator == "+") { | |
//console.log("do add"); | |
return add(num1,num2); | |
} | |
else if(operator == "*") { | |
//console.log("do multiply"); | |
return multiply(num1,num2); | |
} | |
return 0; | |
} | |
console.log(calculate(3,7,"+")); | |
console.log(calculate(3,7,"*")); | |
console.log(calculate(3,7,"-")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment