Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Template literal challenge passes with incorrect code #274

Open
joshalling opened this issue Aug 25, 2018 · 2 comments
Open

Template literal challenge passes with incorrect code #274

joshalling opened this issue Aug 25, 2018 · 2 comments

Comments

@joshalling
Copy link
Member

Describe the bug

The challenge passes if you hardcode three array values into your function.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. use the following code
const resultDisplayArray = [
    `<li class="text-warning">${arr[0]}</li>`,
    `<li class="text-warning">${arr[1]}</li>`,
    `<li class="text-warning">${arr[2]}</li>`
  ];
  1. The tests pass when they shouldn't

Expected behavior

This is problematic because the given function will not work with arrays that have more or less than 3 values.

@johnkennedy9147
Copy link
Contributor

Not sure why you think that is incorrect code. The challenge is to solve a specific problem using template literals, whether to map, loop or use another method on the result array or hardcode references to the array is up to the camper. There is no requirement to consider anything other than the provided 3 element array - result.failure

@joshalling
Copy link
Member Author

joshalling commented Aug 25, 2018

I just think that allowing a solution like this teaches a bad practice as it only works correctly if the array passed has exactly three values. What if your failures array has four values? The 4th value would not be displayed.

I get that the point of this challenge is to teach template literals and this answer does show an understanding of that principle. But if I look at this and ask myself if it's good code, I would argue that it isn't. Maybe the solution to this issue is to just rework the challenge itself so that it is more focused on template literals.

Another thing to think about is that when b8d004e goes to production you will be able to paste the existing comment from the challenge into your function and get it to pass as shown below.

function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray = null;
  // change code above this line

  return [ `<li class="text-warning">no-var</li>`,
   `<li class="text-warning">var-on-top</li>`, 
   `<li class="text-warning">linebreak</li>` ];
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants