JavaScript from Null: Chapter 4
The Full Series
JavaScript University continues today as we learn about methods of the Array object, how to return values from functions, scope, and even your first animation.
Remember – though each new chapter builds upon the previous ones, you can still follow along perfectly well if you haven’t watched the other entries in the series!
In this Screencast, you’ll Learn:
- Methods of the Array object: push, pop, unshift, shift
- Pull values outside of functions
- Reducing your “global footprint” by creating an object
- SetInterval
- Create your first animation
- Methods of the String object.
Chapter 4: Arrays, Functions, and your First Animation
Other Viewing Options
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for the best web development tutorials on the web. Ready
Ready to take your skills to the next level, and start profiting from your scripts and components? Check out our sister marketplace, CodeCanyon.



RoyalSlider – Touch-Enable ... only $12.00 
Great tutorial!
I have some problem when im trying to implement this into a eventListener. Im already spawning the element on a eventListener. But I wanna add another function where I can fade the element in.
var hiddenElement = document.getElementById(‘hiddenElement’);
hiddenElement.addEventListener(‘click’, fadeIn, false);
function fadeIn() {
setInterval(function() {
hiddenElement.style.opacity += .08;
}, 1000 );
}
Any help would be appreciated :)
Forgot to say that only want it to run ones on the ‘click’.
Hi
Javascript is trying to do string concatenation.
The following code should work as a basic example:
YOUR CODE
var box = document.getElementById(‘box’);
var currentOpacity = parseFloat(box.style.opacity);
setInterval(function(){
currentOpacity += 0.02;
box.style.opacity = currentOpacity;
console.log(currentOpacity)
},100)
Make sure the opacity is set to 0 to begin with.
wut if i wanted to pass in multiple variables to one parameter of the fadeOut function? like using an array?
so i dont have to declare the same function twice.
i.e.
function fadeOut( elem, speed ) {
…
}
fadeOut( [box, anotherbox], 1000 );