Created
December 13, 2009 15:57
-
-
Save ejknapp/255467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This is the JavaScript code for | |
| "Lab 11: Searching an Array" | |
| File: /unit5/labs/lab11searchAnArray.html | |
| */ | |
| function lab11Demo() { | |
| // Your code goes in here. | |
| var words; | |
| var search = "not"; | |
| var index; | |
| var currentWord; | |
| var valueFound = false; | |
| var output; | |
| output = document.getElementById("outputParagraph"); | |
| words = ["Believe", "it", "or", "not", "", "the", "very"]; | |
| for (index = 0; index < words.length; index++) { | |
| currentWord = words[index]; | |
| if (search === currentWord) { | |
| valueFound = true; | |
| break; | |
| } | |
| } | |
| if (valueFound) { | |
| //output the value and the index | |
| output.innerHTML = "We found \"" + currentWord + "\" at index " | |
| + index; | |
| } else { | |
| //output "not found" | |
| output.innerHTML = "not found"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment