Webolution Designs

  • Posted on May 17, 2016 2:21 pm
    math functions

    Math...I know...some of you are letting our a collective groan. Let's face it, not all of us like math, but it is necessary and can be very helpful in developing applications. Fortunately, JavaScript has some built in Math methods to assist us. PI – returns 3.14…. round() – round floating point to nearest integer floor() – round floating point down ceil() – round floating point up random() – generate random number between 0 and 1 There is also, min(), max() and abs(), which returns an absolute number. So if you need to perform any of these mathematical calculations, let the JavaScript engine do it for you. [crayon-5a18ced167006666791371/] Note: If you want a random number between numbers other than 0 & 1, you can do that easily enough... [crayon-5a18ced167019976477453/] Happy Coding! Clay Hess

  • Posted on May 16, 2016 2:50 pm
    words string

    In JavaScript, case matters. It is a case sensitive language. Because of that, you have to keep in mind that when you are working with data, you might have equivalent data, but JavaScript does not see it as such. For example, the string "javascript rules!" is equivalent in data to the string "JavaScript Rules!". Yes, the cases are different, you could argue they are not the same, but they essentially say the same thing. So, say you are comparing two strings and you do not want case to matter. How do you do that? Thankfully, JavaScript provides a way to handle this using one of two methods...toLowerCase() and toUpperCase(). Here is an example... [crayon-5a18ced167920473819548/] You can do the same thing with toUpperCase(). Hopefully, this will help you when you need to compare two strings. Happy Coding! Clay Hess

  • Posted on December 23, 2015 4:10 pm
    search characters

    The method I am going to cover in today's post is very similar to the last post (indexOf). Today, I am going to cover the charAt() method. This string method searches through a string to find a particular character whereas indexOf() is primarily used to find substrings or groups of characters. Let's take a look at an example... [crayon-5a18ced167d4b405031477/] As you can see from above, we pass charAt() a numeric value as opposed to an actual string like indexOf(). This value is the location of the character. This is also zero-based in its indexing count. So the 'c' is in the twelfth position, but since we start with zero, I used eleven (11). So you can utilize this function to pick out certain characters and use them in your coding. For example, say you have a listing of employees and you want to output all of the ones that have a last name that begins with 'P'. Well, you can do something like this... [crayon-5a18ced167d5c640251483/] Happy Coding! Clay Hess

  • Posted on December 22, 2015 3:29 pm
    search string

    In a continuation of my last post, I want to cover another useful method for string objects...indexOf(). I know indexOf() sounds cryptic, but it is fairly straight forward. It simply allows you to search to see if a string contains a substring. A substring is a portion of a string. For example, if I have the following string..."Hello World", then a substring could be "World". So it is a portion of the entire string. Let's see an example... [crayon-5a18ced1681b3621316774/] If you run the aforementioned code, the value of the variable, stringLocation, would be 11. Why 11? Well, indexOf() returns the beginning location in the string where the item for which you are searching begins. Counting is zero-based (begins at zero). So if we count the characters of the string... T - 0 | h - 1 | i - 2 | s - 3 | [space] - 4 | i - 5 | s - 6 | [space] - 7 | a - 8 | n - 9 | [space] - 10 | e - 11 Now that you have the starting location for the substring, you can then perform some string manipulation, but more on that in future posts. Now, what happens if the substring does not exist? Then the indexOf() method returns -1. [crayon-5a18ced1681c4814520887/] In this example, the stringLocation variable would be -1. You could use this in IF statements, etc. Happy coding! Clay Hess

  • Posted on December 21, 2015 4:23 pm
    jumbled string

    Strings are primitive JavaScript objects. Since they are objects, we can tap into some built-in methods to make string manipulation easier. So over the next several posts, I want to delve into a few of these more helpful methods. Today, I want to cover the length property. The length property allows you to count the number of characters in a string. Let's look at an example... [crayon-5a18ced168742211141037/] Cool, huh? Now I know what you may be thinking, "Why not just count that there are twelve characters in the string variable?" You could do that as this one is a simple example, but what if I asked you how many characters are in the Declaration of independence? Aah...not so easy now huh? [crayon-5a18ced168751280220734/] The result of the output of console.log(declarationIndependence.length); would be - 8142...much easier than counting by hand! Happy Coding! Clay Hess