Incorrect Test expectation for Confirm the Ending Challenge
See original GitHub issueChallenge Confirm the Ending has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
- Added console log statements to check the work, and I see that me and name do not match and should be false, but the test is expecting it to be true.
If I understand the challenge correctly, it’s to make sure that the last letter or word in the string matches the target respectively. The last word of the string “He has to give me a new name” is name, and the target is “me”. me and name do not match so the test, confirmEnding(“He has to give me a new name”, “me”) should return true, should actually return false; correct?
My code:
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var match;
if(target.length === 1) {
match = target == str.substring(str.length-1, str.length);
} else {
var words = str.split(" ");
var lastWord = words[words.length-1];
match = target === lastWord;
}
return match;
}
confirmEnding("Bastian", "n");
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Confirm the ending of a string in JavaScript | by Dylan Attal
This is an interesting challenge. We're going to going to be checking if an input string ends with a given target.
Read more >Two ways to confirm the ending of a String in JavaScript
In this article, I'll explain how to solve freeCodeCamp's “Confirm the Ending” challenge. This involves checking whether a string ends with ...
Read more >Discrepancy between my results and Coderbyte results?
I just completed challenge 19 with JavaScript (Second GreatLow). My code returns three incorrect test cases. When I try the incorrect test cases...
Read more >Igcse Physics November 2specimen Paper (Download Only) - www ...
countless students to achieve or exceed their expectations in their GCSE Science exams. This is the companion workbook for the GCSE Triple Physics...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jlheard You know, that’s something I hadn’t considered before. I didn’t realize the confusion was coming from the fact that the word
"me"
appears earlier in the string, so thanks for pointing that out! 😄I like the idea for using the phrase “Open sesame” (with title case to match the other tests rather than camelCase). It might be good to replace these two tests:
with:
They test for similar conditions but should be much clearer without that ambiguity about an earlier-appearing string recurring at the end.
@jlheard thanks for the issue. I also didn’t know where the confusion was coming from.
@BKinahan I like your suggested changes to those two tests 👍