//in regular javascript can use tripple wutotes (''') and anything you put inside there will be your comments
/*(this is close)
height=500
dimension=({height,width})
width=480
// dimension = {1000, 960}
// This block defines a cumulative sum of numbers from 0 to 10
{
letx=0;
for(leti=1;i<=10;++i){
x+=i;
}
returnx;
}
//block content will only be applied in a block, within the curly brackets . The blocks are a subset of the alrger project, as the console is a subset of observable .
x
//this variable is null because not within scope
functionrunning_total(max){
letx=0;
for(leti=1;i<=max;++i)
x+=i;
returnx;
}
running_total(10)
// we get an error above because the variable firstNumber is not within the scope of observable.
/*I could have also done this
function addingNumbers (number1, number2){
let number3 = number1 + number2
return number3
}
*/
{
consta=5;
a=6;
returna;
}
//EB - there are multiple ways to create a new varible . Let, vars. const are ways to do this
//const can not be changed over time
{
letmyfirstVar='hello'
constmyConstantvar'world'
myfirstVar='goodbye'
myConstantvar=hi
}
//note that I can change here the variable (myfirstVar) value that I have defined with let, but I could not change the variable (myConstantvar) that I defined with const
{
leta=5;
a=6
returna+30;
}
//here we are calling the variable within the curly brackets
//since we used let we were able to change the value of the variable (a)
//depending on the data type, they have different functionalities.
1+2
typeof(1+2)
// typeof() will tell you the datatype of the value you give it
1.0+2.5
typeof(1.0+2.5)
2/0
typeof(2/0)
"a"/2
typeof("a"/2)
"hello, world"
typeof"hello, world"
"hello, "+"world"
name="Elizabeth"// Fill your name in here!
`hello, world, it's ${name}`
typeof(`hello, world, it's ${name}`)
'today is ${day}'
//NOT SURE IF I DID THIS RIGHT
9>10
typeof(9>10)
10==10
(9>10)&&(10==10)// Evaluates to false AND true
(9>10)||(10==10)// Evaluates to false OR true
!(9>10)&&(10==10)// Evaluates to NOT(false) AND true
!((9>10)||(10==10))// Evaluates to NOT(false or true)
typeof(x)
{lety
returntypeof(y)
}
//undefined happens when we initiate a variable that we have not yet defined
//defined = assigned a value to it
ra=["one",2,3.0]
//storinh values in a single bucket. can consist of multiple data types. including NA, undefined, etc.
//Next we will learn how to handle and play with arrays
typeofra
ra[0]
ra[3]
functionaddthese(a,b){
returna+b;
}
typeof(addthese)
typeof(addthese(1,4))
//generators dont return an array, they return elements of an array instead
//to define an object (like the ones for the car above)
car=({
make:'fiat',
model:500}
)
// use the ( and { and : // this is observable specific
"hello, world".toUpperCase()
directory={
constdata={"employees":[
{"firstName":"John","lastName":"Doe"},
{"firstName":"Anna","lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]};
returndata
}
//a list of the employees at my company. Every element is an object upon itself.
Array(3)[
0:=
1:
2:
]
directory.employees
directory.employees[1]
directory.employees[1].firstName
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.