Published
Edited
Jan 28, 2020
Insert cell
Insert cell
Insert cell
Insert cell
// DECLARAING A FUNCTION
function myFunctionThatCalculatesASum( parameter1, parameter2 ) {
// CODE BLOCK: do stuff in here
var sumOfMyParamters = parameter1 + parameter2
return sumOfMyParamters // <-- this is outputted from the function
}
Insert cell
// RUNNNING THE FUNCTION
theOutput = myFunctionThatCalculatesASum(true,true)
Insert cell
{
function sum(a,b) {
return a + b
}
function product(a,b) {
return a * b
}
var onePlusTwo = sum(1,2)
var threePlusFour = sum(3,4)
var productOfTwoVariables = product(onePlusTwo, threePlusFour)
return productOfTwoVariables // <-- ignore that return. it's to make the notebook work
}
Insert cell
Insert cell
{
var bob = function () {return "Hi, I'm in Bob!"}
var joe = bob() + " And now I'm called by Joe!"
return joe
}
Insert cell
Insert cell
function checkDay(today) {
if(today === "Sunday" || today === "Saturday") {
return "WEEKEND"
} else {
return "WEEKDAY"
}
}
Insert cell
checkDay("Sunday")
Insert cell
Insert cell
{
// COUNTING TO TEN
var count = 0
while( count != 10 ) {
count = count + 1;
}
return count;
}
Insert cell
Insert cell
Insert cell
Insert cell
{
// COUNTING TO TEN
var count = 0
for( var i = 0; i < 10; i++ ) {
count = count + 1
count = count + 1
count = count + 1
count = count + 1
count = count + 2
count = count + 1
count = count + 1
count = count + 1
count = count + 1
}
return count
}
Insert cell
Insert cell
Insert cell
function testable(isGood) {
if(isGood===true)
return "yes"
return "no"
}
Insert cell
test1 = testable(true)==="yes"
Insert cell
test2 = testable(false)==="no"
Insert cell
test3 = testable(1)==="yes"
Insert cell
Insert cell
Insert cell
function sleepIn(weekday, vacation) {
return undefined;
}
Insert cell
Insert cell
Insert cell
function hasTeen(num1, num2, num3) {
return undefined;
}
Insert cell
Insert cell
Insert cell
function front3(str) {
return undefined;
}
Insert cell
Insert cell
Insert cell
function findPrimes(input)
{
return undefined;
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more