Public
Edited
Jan 16, 2023
Insert cell
Insert cell
Insert cell
Insert cell
function getDate() {
return new Date().toDateString();
}
Insert cell
Insert cell
Insert cell
Insert cell
function getWorkshopDate () {
return new Date(2020, 11, 4).toDateString();
}
Insert cell
Insert cell
Insert cell
Insert cell
function toHex(n) {
let hex = n.toString(16);
return hex.padStart(2, '0');
}
Insert cell
Insert cell
Insert cell
Insert cell
function rgbToHex(R, G, B) {
return '#' + [toHex(R), toHex(G), toHex(B)].join('');
}
Insert cell
Insert cell
Insert cell
Insert cell
function setColor(R, G, B) {
const hex = rgbToHex(R, G, B);
const colorMe = document.getElementById('color-me');
colorMe.setAttribute('style', 'color: ' + hex);
}
Insert cell
Insert cell
Insert cell
Insert cell
async function readJsonFile(filename) {
const file = await fetch(
'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson'
);
return await file.json();
}
Insert cell
Insert cell
Insert cell
Insert cell
function writeJsonString(object) {
return JSON.stringify(object, null, 2);
}
Insert cell
Insert cell
Insert cell
Insert cell
function exclusiveOr(A, B) {
return (A || B) && !(A && B);
}
Insert cell
Insert cell
Insert cell
Insert cell
function computeTruthTable(operator) {
const truthValues = [true, false];
const table = [];
for (const A of truthValues) {
for (const B of truthValues) {
const value = operator(A, B);
table.push({ A, B, value });
}
}
return table;
}
Insert cell
Insert cell
Insert cell
Insert cell
function showTruthTable(operator) {
console.table(computeTruthTable(operator));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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