0

Need some help on a code problem that my instructor did not really explain how to use Key

var terms = []; terms['JavaScript'] = "A really cool programming language"; terms['DOM'] = "When the browser loads a page, it creates a model of objects that represent each tag in the html (DOM stands for Document Object Model)"; terms['Array'] = "array is a single variable that is used to store different elements"; terms['Variable'] = "Variable means anything that can vary. JavaScript includes variables which hold the data value and it can be changed anytime. JavaScript uses reserved keyword var to declare a variable."; terms['Events'] = "interaction with HTML is handled through events that occur when the user or the browser manipulates a page. When the page loads, it is called an event."; // Problem 2 - Write a program to allow users to look up terms and definitions // Use the prompt() function to ask the user which JavaScript term they would like to look up (from the 'terms' array in problem 1). // Then use the alert() function to display the definition of the term. // If the term is not in the array, then display "That term is not in the array" in the alert message. var termsQ = prompt("Which javascript would you like to look up?"); var selectedTerm; console.log(termsQ); console.log(terms[key]); for( var key in terms){ if( termsQ == terms[key]){ var termsQ console.log(termsQ) } } if(selectedTerm){ alert("You Selected " + selectTerm) }else{ console.log(selectedTerm) }

26th Nov 2019, 7:56 PM
Christian Bonilla
Christian Bonilla - avatar
1 Odpowiedź
0
text below pasted from:- https://www.w3schools.com/js/js_arrays.asp "Associative Arrays Many programming languages support arrays with named indexes. Arrays with named indexes are called associative arrays (or hashes). JavaScript does not support arrays with named indexes. In JavaScript, arrays always use numbered indexes. "
26th Nov 2019, 8:23 PM
rodwynnejones
rodwynnejones - avatar