SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    New Member
    Join Date
    Jul 2012
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    beginner Javascript Question

    Hello - I'm just getting started leaning JavaScript to support some testing automation. The exercise I'm having trouble with requires me to write a function that returns a count of the number of letter "D"'s in the function input parameter string.

    However I get this error when I run it:
    TypeError: Object doesn't support property or method 'charAT' (line 4 in function countDs)

    Here's my code. Does anyone see an issue?

    function countDs(word) {
    var newString = "";
    for (N = 0; N <= word.length; N++)
    if (word.charAT(N) == D)
    newString = newString + "D";
    return newString.length;
    }


    console.log(countDs("DDC"));

    Thanks for any help!!!

  2. #2
    New Member
    Join Date
    Oct 2015
    Location
    Boston
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    It means exactly what it says. It can't find the method 'charAT' for that string. However strings do have a 'charAt' method. Capitlization matters a great deal.

    if your still having trouble. This was a month ago, so i'm sure you figured it out, but regardless here is a quick fiddle in case anyone searches for a similar issue and isn't able to figure it out.

    https://jsfiddle.net/noxwc8wj/

  3. #3
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,619
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by Bryan C. Winter View Post
    It means exactly what it says. It can't find the method 'charAT' for that string. However strings do have a 'charAt' method. Capitlization matters a great deal.

    if your still having trouble. This was a month ago, so i'm sure you figured it out, but regardless here is a quick fiddle in case anyone searches for a similar issue and isn't able to figure it out.

    https://jsfiddle.net/noxwc8wj/
    Cool thing about JavaScript is regular expressions is a first class object built into the language.

    https://jsfiddle.net/d2ayd7tw/1/
    David Lai
    SDET / Consultant
    LinkedIn profile

  4. #4
    New Member
    Join Date
    Sep 2016
    Location
    mumbai
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    It should not be charAT as it should be charAt

 

 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 6.90%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:06 PM.

Copyright BetaSoft Inc.