Skip to content

Instantly share code, notes, and snippets.

@mshumer
Created December 16, 2021 02:50
Show Gist options
  • Save mshumer/4946b588b9855c44236bc9bfc9e00a11 to your computer and use it in GitHub Desktop.
Save mshumer/4946b588b9855c44236bc9bfc9e00a11 to your computer and use it in GitHub Desktop.
/*(<seed> ////write a javascript function to say Hello World!..
//but try to avoid this error: Unexpected identifier
</seed>)
<stop>});</stop>
<codeType>unknown</codeType>*/
function sayHelloWorld() {
console.log('hello world!');
}
//write a function that takes two arguments and returns the sum of them
function add(a,b){
return a+b;
}
//write a function that takes an array of numbers as an argument and returns the average value of those numbers
function avg(arr){
let sum = 0; //initialize our variable to 0 so we can add up every value in our array later on...
for (let i=0;i<arr.length;i++){ //loop through each element in our array...
sum += arr[i]; //add up all the values in our array and store it in our variable called "sum"..
}
return sum / arr.length; //divide the total by the number of elements in our array to get the average value..
}
/*<output>{
"console": {}
}
</output>*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment