ProgramsJavaScript

Basic Programs

console.log, let, a bit of math. Week-one JS. If this feels slow, skip ahead.

10 programs · open one, then the next

Start with Hello World
  1. 01Hello WorldBeginnerOne console.log. If this prints, Node or the browser console is actually working.Open example →
  2. 02Display Your NameBeginnerlet name = "...". console.log can take extra arguments. They get spaces between them.Open example →
  3. 03User InputBeginnerprompt() in the browser. Node has no prompt unless you install something.Open example →
  4. 04Sum of Two NumbersBeginnerAdd two numbers. Coerce the strings or you glue 10 and 20 into 1020.Open example →
  5. 05Swap Two NumbersBeginnerTemp variable, then destructuring. The second one is the one you keep.Open example →
  6. 06JavaScript Data TypesBeginnertypeof null is "object". That is a bug from 1995. Live with it.Open example →
  7. 07Arithmetic OperationsBeginner+ - * / % **. / is float. % is remainder. ** is power. ^ is XOR.Open example →
  8. 08Convert Fahrenheit to CelsiusBeginnerC = (F - 32) * 5/9. 32°F should be 0. If you get 17.7 you forgot the minus 32.Open example →
  9. 09Calculate Simple InterestBeginnerP*R*T / 100. Rate 5 means 5%, not 0.05.Open example →
  10. 10Area and Perimeter of RectangleBeginnerarea = l*w. perimeter = 2*(l+w). Height is not a diagonal.Open example →