If the point of the sentinel is to, as the wiki article says: >The basic algorithm above makes two comparisons per iteration: one to check if Li equals T, and the other to check if i still points to a valid index of the list. By adding an extra record Ln to the list (a sentinel value) that equals the target, the second comparison can be eliminated until the end of the search, making the algorithm faster. Then the approach should be to *tack on* the value to find onto the end of the array, instead of *replacing* the last value of the array with the value to find. I guess you *can* replace the last value, then once a match is found, replace it back, then check it, but that's unnecessarily convoluted. Your code has a bug: if the first element of the array is the item to search for, `while (array1[i] !== x) {` will evaluate to `false`, and the IIFE will terminate immediately without logging anything. That test is superfluous anyway, since inside the loop, the array item will either be found before the end, or at the end - either way, `console.log` will be called. To add an element to the end of an array in JS, it's easier to use `push`: ``` array1.push(x); ``` You might consider using more precise variable names, to make the code more readable. (I'd avoid using single-letter variable names except maybe for `i`, which is pretty universally understood to be an index.) <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> const linearSearchSentinel = (array, itemToFind) => { const { length } = array; array.push(itemToFind); (function () { let i = 0; while (true) { if (array[i] === itemToFind) { if (i === length) { return console.log('NOT FOUND'); } return console.log('FOUND ON INDEX', i); } i++; } })(); array.shift(); // remove the added item from array }; linearSearchSentinel(['foo', 'bar', 'baz'], 'foo'); linearSearchSentinel(['foo', 'bar', 'baz'], 'baz'); linearSearchSentinel(['foo', 'bar', 'baz'], 'nope'); <!-- end snippet --> It's also a good idea to [prefer `const`](https://softwareengineering.stackexchange.com/questions/278652/how-much-should-i-be-using-let-vs-const-in-es6) over `let` when you don't need to reassign the variable name.