DHSI - Javascript & D3 Day 3

less than 1 minute read

Published:

Notes

Recap

  • SVG are written in xml and each has its own attributes.

  • Data types variables, arrrays, objects, and functions


function flipcoin(){
  coin = Math.random();
  console.log(coin);
    if (coin > 0.5);
    return "heads";
  } else
  { return "tails";
}

DOM part 2

The document object, above the html object, can be used to modify the DOM including removing, adding, and modifying elements. The browser redraws the DOM every time it is changed.

Functions part 2

Prewritten functions work more or less the same as in python. Global variables are available to all functions. Local variables are only available within the function. You can pass properties, variables, and functions to other functions. You can also have anonymous functions that are not named and are only used once (lambda in python). For ex.

concierge( function(msg) {document.write(msg); }, 'Error!');

Or in arrow notation which is much shorter and cleaner:

concierge( msg => document.write(msg), 'Error!');

‘div’ blocks are used to group elements together. They can be styled with CSS.