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

Friday, December 7, 2012

LearnStreet Javascript Lesson 6 Exercise 3


//sample solution


function stringDistance(str1, str2){
    /*Complete the code below to go through two strings
      and return the number of letters that do not match.
      Assume both str1 and str2 have the same length. **/

    var numMismatch = 0;

    var index = 0;
    while (index<str1.length) {
        if (str1.charAt(index)!==str2.charAt(index)) {
            numMismatch++;
        }
        /*your code here to increment index*/
        index++;
    }
    return numMismatch;
}
//test
stringDistance("dog","cat");

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts