Intro to Code Part VI – JavaScript Conditionals

woman writing code

The best answers lead to more questions.

In the sixth part of our Intro to Code series, we reviewed JavaScript conditionals and also solved several algorithm challenges. This format will be the new normal for the next few sessions as we take our JavaScript skill set from the point where we understand basic syntax to the point where we can use it to solve problems.

Conditionals — if / else and switch statements — are used to make your programs smarter. With conditionals, your code can produce different results depending on what information is passed to it. All but the simplest programs will require the use of conditionals.

We started class with a quick view of this type of code and from there we went immediately into algorithms. We eased into these starting with simple problems and a little pre-written code but we moved quickly into more difficult challenges that we solved from scratch.

Three of our algorithm challenges were taken from Free Code Camp and we’ll be spending more time on that site over the next two weeks as our homework requires us to solve the first ten of FCC’s Basic Algorithm Scripting Challenges.

Here’s a link to the slides from part six.

For the homework, you’ll want to create an account on Free Code Camp. FCC is a great resource in general.

Our homework challenges start HERE. Complete all ten!

In our next session, we’ll review JavaScript loops and arrays and solve yet more algorithms. In just a short while we’ll have enough of a JS skillset to start building actual web applications.

Code on!

4 thoughts on “Intro to Code Part VI – JavaScript Conditionals

  • Thank you Matt for the sixth part! I was struggling with factorial. So some reason FCC does not like my code but it works in and equals 120 as it should be.

    function factorial(n) {

    return (n != 1) ? n * factorial(n – 1) : 1;

    console.log (factorial(5) );

  • Hi Max,

    It looks like you’re trying for a recursive solution to the problem, which is clever. Your syntax is a bit off, though.

    function factorialize(n) {
    return (n !== 0 ? n * factorialize(n -1):1);

    The differences: In JavaScript does not equals is !==. Otherwise, it’s not type-sensitive. Also, your parenthesis are off. I think FCC will want you to call the function ‘factorialize’ as well since that is their name for it.

Leave a Reply

Your email address will not be published. Required fields are marked *