This is my first javascript lesson. Hello is displayed when the page is opened, but the script is not executed. Why?

<html> <head> <title>Object Oriented Javascript</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> Hello!!! <script type="text/javascript"> var customer = { name: "Tom Smith", speak: function(){ return "My name is " + this.name; }, address: { street: '123 Main St', city: "Pittsburgh", state: "PA" } }; document.write(customer.speak() + <br />); </script> </body> </html> 

Closed due to the fact that off-topic participants Grundy , 0xdb , user192664, aleksandr barakin , αλεχολυτ Oct 12 '18 at 14:01 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Grundy, 0xdb, Community Spirit, aleksandr barakin, αλεχολυτ
If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    Error here document.write(customer.speak() + <br />); It is necessary <br /> to quote.
    Read more here https://learn.javascript.ru/document-write

      Why is the script not running?

      as Alexander said: you have a typo.

      Read more here https://learn.javascript.ru/document-write

      and here https://developer.mozilla.org/ru/docs/Web/API/Document/write

      how to avoid typos, recommendations to a newbie javascript

      eg

      how to google google search javascript

      search MOZILLA documentation using a Google search engine like this: MDN [искомый метод]

       MDN document.write MDN insertAdjacentElement MDN insertAdjacentHTML MDN insertAdjacentText MDN innerHTML 

      search site learn.javascript.ru using a search engine from google like this: site:learn.javascript.ru [искомая информация]

       site:learn.javascript.ru document.write site:learn.javascript.ru insertAdjacentElement site:learn.javascript.ru insertAdjacentHTML site:learn.javascript.ru insertAdjacentText site:learn.javascript.ru innerHTML 

      recommend

      I strongly recommend you to get acquainted with this trinity

       let el: HTMLElement el.insertAdjacentElement el.insertAdjacentHTML el.insertAdjacentText 

      small example:

       /** * @type {HTMLElement} */ let el = document.body /** * @type {HTMLDivElement} */ let div = document.createElement('div') div.innerHTML = `i'am div` el.insertAdjacentElement('beforeend', div) el.insertAdjacentHTML('beforebegin', '<h1>head</h1>') el.insertAdjacentText('beforeend', '<p>just text<p>') /** * @param {HTMLElement} el */ function HTML(el) { /** * @param {TemplateStringsArray} t * @param {any[]} s */ function html(t, ...s) { el.insertAdjacentHTML('beforeend', String.raw(t, ...s)) } return html } let html = HTML(div) html` <br>add some text to <b>div</b> ` const LI = _str => `<li>${_str}</li>` html` <ul> ${[1, 2, 3, 4, 5].map(LI).join('')} </ul> ` html` <ul> ${Array.from({ length: 8 }, (v, i) => LI(i)).join('')} </ul> ` 

      • And how to debug it? tinplate .. - Drakonoved
      • @Drakonoved, m? what is it? for example, the LI function will always work! here, look u.to/z7DJEw - qwabra