hw07_02literals_expand.html 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. <header>
  2. <h1>Literals expand</h1>
  3. </header>
  4. <body>
  5. <script>
  6. const cat =
  7. {
  8. "head":
  9. {
  10. "name": "cat's head",
  11. "ears": [{ "name": "ear", "attrs": { "position": "left" } }, { "name": "ear", "attrs": { "position": "right" } }],
  12. "eyes": [{ "name": "eye", "attrs": { "position": "left" } }, { "name": "eye", "attrs": { "position": "right" } }],
  13. "mouth": "cat's"
  14. },
  15. "body":
  16. {
  17. "name": "cat's body",
  18. "paws":
  19. [
  20. { "name": "paw", "attrs": { "position": "left", "placement": "front" } },
  21. { "name": "paw", "attrs": { "position": "right", "placement": "front" } },
  22. { "name": "paw", "attrs": { "position": "left", "placement": "rear" } },
  23. { "name": "paw", "attrs": { "position": "right", "placement": "rear" } },
  24. ],
  25. "tail": "cat's tail"
  26. }
  27. }
  28. cat[prompt("Enter property name")] = prompt("Enter property value");
  29. cat[prompt("Enter property name")] = prompt("Enter property value");
  30. </script>
  31. </body>