Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Does any one have any project ideas to help with conditional statements and functions?

I'm looking to build a list of project ideas to help get down conditional statements and functions.

1 Answer

Depends on how comfortable you are with some of the other basic concepts of JS (i.e. loops, objects, arrays). I'd say try to mimic some of the functions that are already in JS. You'll have to use conditionals in those functions quite often so it will help you practice both. For instance:

// Returns the index of a value in an array
// If value isn't in array, return -1
function find(arr, value) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] === value) {
            return i;
        } else {
            continue;
        }
    }
    return -1;
}

find([1,2,3], 3) // => 2
find([1,2,3], 5) // => -1

This function gives the same functionality as the Array.indexOf() method.

This exercise will help you in learning how to write functions and conditionals, while also helping you learn about some of the different functions and methods that are already available to in JS and how they work.

But like I said, you'll probably need to get mildly comfortable with all of the basics to really get into some of the more complicated native JS functions.