Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Having an issue with the output in Visual Studio for JavaScript
Post Flair (click to view more posts with a particular flair)
Post Body

I was able to run this code using an online compiler and it provided the right output, which is:

4

0

null

However, I installed JavaScript on Visual Studio and I can't seem to get it to produce the same output. I can see that I can change the "Show output from" to several different options, but none of them give me the output I'm looking for. The Debug option just keeps printing "Hello world."

This is the code:

function simpleSearch(target, arr) {

for (let i = 0; i < arr.length; i  ) {

    if (arr[i] === target) {

        return i;

    }

}
return null;

}

// Testing code, calls the function.

console.log(simpleSearch(5, [1, 2, 3, 4, 5])); // Should print 4

console.log(simpleSearch("a", ["a", "b", "c", "d", "e"])); // Should print 0

console.log(simpleSearch(2, ["a", "b", "c", "d", "e"])); // Should print null

Author
Account Strength
100%
Account Age
9 years
Verified Email
Yes
Verified Flair
No
Total Karma
6,453
Link Karma
2,306
Comment Karma
4,147
Profile updated: 2 days ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
9 months ago