Published
Edited
Insert cell
Insert cell
Insert cell
Insert cell
// Import the addition or multiplication function from this notebook
//Notebook Link: https://observablehq.com/@rakshith/practice-examples-for-functions-and-import
Insert cell
//Code to import
import { name of the function } from " provide notebook link here"
Insert cell
//Call the function with 2 input values to display the result
//ex: division(2,6)
Insert cell
Insert cell
{ var num1 = 14;
var num2 = 7;
function division(a, b) {
return a / b }
division(num1 / num2)
}
Insert cell
{ var result = division(14, 7) }
function division(a, b) {
return a / b;
}

Insert cell
Insert cell
md `#### Reemeber to declare a variable using **"Var"** keyword in inside the brackets{ }`
Insert cell
{ let array = ['zero', 'one', 'two'] }
Insert cell
{ let nestedArray = [
['zero', 0]
['one', 1]
['two', 2]
]
}
Insert cell
{ function accessArray(arr) {
return arr[0][1]
}
}
Insert cell
accessArray(nestedArray)
Insert cell
Insert cell
//Create a Global objects with 2 properties(values) to be displayed in a bar chart
//example 1
Insert cell
{// Create an object with 2 properties and 1 method
//example 2
}
Insert cell
md `### Arrays, Objects with functions`
Insert cell
{ //Create an array with Objects inside it
}
Insert cell
{ //Object inside an Object
}
Insert cell
{ //Create an Object with arrays inside
}
Insert cell
Insert cell
{//Import a slider function from other notebook}
Insert cell
{//Call the function and give it to a bar chart input}
Insert cell
md `## Start to End process with Vega-Lite**`
Insert cell
Insert cell
import {slider} from '@jashkenas/inputs'
Insert cell
viewof si = slider()
Insert cell
si
Insert cell
alphabet = FileAttachment("alphabet.csv").csv() // about file attachments https://observablehq.com/@observablehq/file-attachments
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
alphabet[0] // what a row of data in `alphabet` looks like
Insert cell
// about viewof https://observablehq.com/@observablehq/a-brief-introduction-to-viewof
viewof simpleBar = vl.markBar() // Make a bar chart
.data(alphabet) // Using the alphabet data
.encode(
vl.x().fieldO("letter"), // .sort(vl.fieldQ("frequency").order("descending")), // Letters are ordinal on the x-axis
vl.y().fieldQ("frequency").axis({ format: "%" }) // Frequency on the y-axis, formatted as percent
)
.render()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more