WDD 330 portfolio
Week 03
Notes
-
Methods: functions inside a class
Adding methods to an object super easy without having to create a class.
Use Objects to be prepared for the todo list assignment
-
Events: events are actions or occurrences that happen in the system you are programming
Events are fired inside the browser window, and tend to be attached to a specific item that resides in
it — this might be a single element, set of elements, the HTML document loaded in the current tab, or
the entire browser window.
-
The earliest method of registering event handlers found on the Web involved event handler HTML
attributes
Questions
-
Are methods very popular?
Code Examples
-
const btn = document.querySelector('button');
function random(number) {
return Math.floor(Math.random() * (number+1));
}
btn.onclick = function() {
const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
document.body.style.backgroundColor = rndCol;
}
-
const btn = document.querySelector('button');
btn.onclick = function() {
const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
document.body.style.backgroundColor = rndCol;
}