question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect Test expectation for Confirm the Ending Challenge

See original GitHub issue

Challenge 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.

  1. 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?

screen shot 2016-07-21 at 2 03 09 pm

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:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
BKinahancommented, Jul 21, 2016

@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:

confirmEnding("He has to give me a new name", "me") should return true. confirmEnding("He has to give me a new name", "na") should return false.

with:

confirmEnding("Open sesame", "same") should return true. confirmEnding("Open sesame", "pen") should return false.

They test for similar conditions but should be much clearer without that ambiguity about an earlier-appearing string recurring at the end.

0reactions
erictleungcommented, Jul 21, 2016

@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 👍

Read more comments on GitHub >

github_iconTop 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 >
freeCodeCamp - Confirm the Ending - YouTube
GitHub: https://github.com/ChrisCooper0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found