Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, December 7, 2012

LearnStreet Javascript Lesson 6 Exercise 4


//sample solution


function equal(str1, str2) {
    /*Complete the code below to check if two strings
      are equivalent, i.e. each and every character matches.*/

    /*If the lengths are not equal, there is no point comparing
      each character. We already know they can't be equal!*/
    if (str1.length != str2.length) {
        return false;
    }

    /*Write your while loop here to go through each position
      and check if they are equal in both strings. Return
      true or false appropriately. */
    var index = 0;
    while (index<str1.length) {
        if (str1.charAt(index)!==str2.charAt(index)) {
            return false;
            break;
        }
        index++;
    }
    return true;
}
equal("dog","Dog");

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts