Insert cell
Insert cell
3 // I'm a comment. #ComputerCantTouchThis
Insert cell
3 + 3 //addition
Insert cell
4 - 3 //subtraction
Insert cell
2 * 3.2 //multiplication
Insert cell
1 / 5 //division
Insert cell
10 % 3 //modulo
Insert cell
10 ** 3 //exponentiation
Insert cell
Insert cell
Insert cell
typeof 123
Insert cell
typeof 0.1
Insert cell
typeof "this is a string" // denoted by either "string value goes in here",
//'string value in here', or `string value in here`
Insert cell
typeof 'this is also a string'
Insert cell
typeof ""
Insert cell
typeof true // either true of false
Insert cell
typeof false
Insert cell
typeof undefined // the only possible value of an undefined type is undefined
Insert cell
// `typeof` doesn't work with `null` values for backwards compatability reasons.
typeof null
// when checking if something's explicitly `null`, make sure to use null === null
Insert cell
Insert cell
true && true // the AND (&&) operator checks if both values are true
Insert cell
//if either one or both ANDed values are false,
true && false
//the operation returns false
Insert cell
true || true // the OR (||) operator checks if either value is true
Insert cell
//if one value is false, the result is still true
true || false
Insert cell
!true //The NOT (!) operator switches the boolean value
Insert cell
//Order of operations still applies in boolean algebra
!true && false || false || false
Insert cell
!(true && false) || false || false
Insert cell
Insert cell
25 < 2 //notice that these operators take two numbers and output a boolean
Insert cell
25 > 2
Insert cell
2 <= 2
Insert cell
3 >= 2
Insert cell
Insert cell
2+2
Insert cell
'Luke, ' + 'I ' + 'am ' + 'your ' + 'father.'
Insert cell
"I am " + 4 + " years old."
Insert cell
Insert cell
Insert cell
3 === 3
Insert cell
3 === 2
Insert cell
"1" === 1
Insert cell
2 !== 4
Insert cell
Insert cell
{
var name = 'bob'
return name //this line is to make Observable happy
}
Insert cell
Insert cell
Insert cell
Insert cell
{
var num = 1
num = 2
return num
}
Insert cell
Insert cell
{
var one = 1
var two = 2
var three = one + two
return three
}
Insert cell
{
var firstName = 'Bob'
var lastName = 'Marley'
var fullName = firstName + ' ' + lastName
return fullName
}
Insert cell
{
var allMenAreMortal = true
var iAmAMan = true
return allMenAreMortal && iAmAMan
}
Insert cell
Insert cell
day = "Sunday"
Insert cell
{
var hoursBilled = 0
if(day !== "Sunday" && day !== "Saturday") {
hoursBilled = 8
}
return hoursBilled
}
Insert cell
Insert cell
Insert cell
function converter (fahrenheit)
{
return //Your code here
}
Insert cell
Insert cell
Insert cell
function varWars1() {
var smartiesBot = true;
var sourBot = false;
var otherSourBot = sourBot;
return (smartiesBot && sourBot) || otherSourBot
}
Insert cell
Insert cell
function varWars2() {
var smartiesBot = true;
var sourBot = true;
var otherSourBot = false;
return !(smartiesBot || sourBot || otherSourBot)
}
Insert cell
Insert cell
function varWarsArmageddon() {
var smartyKing = true;
var sourKidKing = false;
var smartiesBot = sourKidKing;
var thatOneSourBot = smartyKing;
return smartiesBot && smartyKing || sourKidKing && sourKidKing && thatOneSourBot && thatOneSourBot || (!smartiesBot && smartiesBot || sourKidKing)
}
Insert cell
Insert cell
Insert cell
function colorPicker(color) {
//It's OK that the code below spans multiple lines - Javascript reads it all as one line.
//The code just covers multiple lines so that we humans can read it better :)
return true &&
color === 'purple' ||
color === 'green' ||
color === ('blue' || 'Blue') ||
color !== 'aquamarine' ||
color === 'red' &&
color > ""
}
//Psst... If you want hints on what isn't working in your code, look at the error messages below!
Insert cell
Insert cell
Insert cell
function sleepIn(weekday, vacation) {
return //your code here
}
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