Loops and arrays

Yesterday we covered functions in JavaScript.  It was pretty basic stuff, like adding two numbers together or checking if one number is greater than another.  I’ve done a lot of JavaScript practice prior to this so most of it was review but I did still learn a couple things.  For example, if you have a function that checks whether the first number given is greater than the second number given you could do an if/else statement and say



function isGreater(num1, num2) {


if(num1 > num2) {


return true;


} else {


return false;


}


}

However, a much simpler and shorter solution is to just return the value of the expression num1 > num2.



function isGreater(num1, num2) {


return num1 > num2;


}

Both functions are valid and provide the correct response, sometimes it’s just a matter of thinking through the problem and seeing if and where you can reduce or combine your steps.

Today we are covering loops and arrays.  I like loops because it really requires you to think through each step of a problem and what you need to do to solve it.