# \[#wh6\]\[JS\] can't get the desired output

**URL:** <https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867>\
**Category:** Bug Reports\
**Tags:** challenge:shell\
**Created:** [March 16, 2025, 5:59am UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867 "2025-03-16T05:59:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![semojan](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/semojan/32/5922_2.png) [@semojan](https://forum.codecrafters.io/u/semojan)\
**Post date:** [March 16, 2025, 5:59am UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/1 "2025-03-16T05:59:22Z")

</div>

I’m stuck on Stage #wh6.

My code’s logic seems fine, but it seems there is some issue running it.

Here are my logs:

```auto
 Typed "xyz_"
remote: [your-program] $ xyz_
remote: [tester::#WH6] ✓ Prompt line matches "$ xyz_"
remote: [tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_foo xyz_qux xyz_quz")
remote: [tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_foo xyz_qux xyz_quz")
remote: [tester::#WH6] Output does not match expected value.
remote: [tester::#WH6] Expected: "$ xyz_"
remote: [tester::#WH6] Received: "$ xyz_ "

```

And here’s a snippet of my code:

```JavaScript
if (lastCompletion.prefix === line) {
      lastCompletion.count++;
    } else {
      lastCompletion.prefix = line.trim();
      lastCompletion.count = 1;
      lastCompletion.hits = hits;
    }

    if (line.trim() === "") {
      return [builtin, line];
    }

    if (hits.length === 0) {
      process.stdout.write("\x07"); // Bell sound
      return [[], line];
    } else if (hits.length === 1) {
      lastCompletion.count = 0;
    }

    if (lastCompletion.count === 1) {
      process.stdout.write("\x07"); // Bell sound
      return [[], line];
    } else if (lastCompletion.count === 2) {
      console.log();
      console.log(hits.join(" "));
      return [[], line];
    }

```

I tried logging my variables in different blocks and realized these:  
There is no issue with updating the lastCompletion  
If I don’t log anything before the condition with count === 2, it won’t run, and even if I log something before it It sometimes run and sometimes doesn’t.  
Actually the main issue seems to be that my code sometimes reaches that condition and sometimes just doesn’t.

```auto
console.log(lastCompletion)
    if (lastCompletion.count === 1) {
      console.log(lastCompletion)
      process.stdout.write("\x07"); // Bell sound
      return [[], line];
    } else if (lastCompletion.count === 2) {
      console.log(lastCompletion)
      console.log("\n" + hits.join(" "));
      return [[], line];
    }

```

```auto
Pressed "<TAB>" (expecting autocomplete to "xyz_baz xyz_foo xyz_quz")
remote: [tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_baz xyz_foo xyz_quz")
remote: [tester::#WH6] Output does not match expected value.
remote: [tester::#WH6] Expected: "$ xyz_"
remote: [tester::#WH6] Received: "$ xyz_{ prefix: 'xyz_', count: 1, hits: ['xyz_baz', 'xyz_quz', 'xyz_foo'] }"
remote: [your-program] { prefix: 'xyz_', count: 1, hits: ['xyz_baz', 'xyz_quz', 'xyz_foo'] }
remote: [your-program] { prefix: 'xyz_', count: 2, hits: ['xyz_baz', 'xyz_quz', 'xyz_foo'] }
remote: [your-program] { prefix: 'xyz_', count: 2, hits: ['xyz_baz', 'xyz_quz', 'xyz_foo'] }
remote: [your-program] xyz_baz xyz_foo xyz_quz  

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 16, 2025, 6:10am UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/3 "2025-03-16T06:10:44Z")

</div>

Hey @semojan, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![semojan](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/semojan/32/5922_2.png) [@semojan](https://forum.codecrafters.io/u/semojan)\
**Post date:** [March 16, 2025, 6:27am UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/4 "2025-03-16T06:27:29Z")

</div>

Hello @andy1li  
This is my code uploaded to GitHub:

> **[GitHub - semojan/shell: CodeCrafters' build your own shell challenge](https://github.com/semojan/shell)**
>
> CodeCrafters' build your own shell challenge

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 18, 2025, 3:30pm UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/6 "2025-03-18T15:30:45Z")

</div>

@semojan It turns out that using readline‘s completer in node.js can cause unexpected issues with our testers.

We will investigate this next week and provide an update as soon as we have more details.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 7, 2025, 6:48pm UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/7 "2025-04-07T18:48:20Z")

</div>

Hey @semojan, we’ve resolved the issue in [this PR](https://github.com/codecrafters-io/shell-tester/pull/119). Let me know if everything works as expected now!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 14, 2025, 6:48pm UTC](https://forum.codecrafters.io/t/wh6-js-cant-get-the-desired-output/6867/9 "2025-04-14T18:48:22Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
