Header Ads

Write a JavaScript Program to create a word-meaning dictionary of 5 words

The below code defines a JavaScript object called "dict" which contains 5 key-value pairs, each representing a word and its meaning. The full dictionary can be accessed by using console.log(dict). To access a specific meaning from the dictionary, you can use dot notation and the key of the desired word, for example: console.log(dict.xeriscaping) which would print "environmental design of residential and park land using various methods for minimizing the need for water use."


Code :

const dict = {
  xeriscaping: "environmental design of residential and park land using various methods for minimizing the need for water use.",
  bobèche: "a slightly cupped ring placed over the socket of a candleholder to catch the drippings of a candle.",
  vaudevillian: "of, relating to, or characteristic of vaudeville.",
  ignescent: "emitting sparks of fire, as certain stones when struck with steel.",
  smaragdine: "emerald-green in color."
}

// to access the full dictionary
console.log(dict)

// to access the particular element from the dictionary
console.log(dict.xeriscaping)

Output :

{
  xeriscaping: 'environmental design of residential and park land using various methods for minimizing the need for water use.',
  'bobèche': 'a slightly cupped ring placed over the socket of a candleholder to catch the drippings of a candle.',
  vaudevillian: 'of, relating to, or characteristic of vaudeville.',
  ignescent: 'emitting sparks of fire, as certain stones when struck with steel.',
  smaragdine: 'emerald-green in color.'
}
environmental design of residential and park land using various methods for minimizing the need for water use.





Explanation :

This code defines a constant JavaScript object named dict that contains 5 key-value pairs, where each key is a word and its corresponding value is the definition of that word. The const keyword means that the value of dict cannot be reassigned.

The full dictionary can be logged to the console by calling console.log(dict). This will print the entire object, including all of its key-value pairs.

To access a specific definition from the dictionary, you can use dot notation and the key of the desired word. For example, console.log(dict.xeriscaping) will log the definition of the word "xeriscaping" to the console. This is because dict.xeriscaping accesses the value associated with the key "xeriscaping" in the dict object.





Related Links :











Post a Comment

0 Comments