Why doesn't the computer speak the text in ```<body>``` element when I click on it?

Why doesn’t the computer speak the text in <body> element when I click on it?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="style.css">
</head>
<body onclick="confirm(this.textontent)?speechSynthesis.speak(new SpeechSynthesis(this.textContent)):"";'>
Good morning!
</body>
</html>

Hello.

There are few problems:

  1. textContent, not textontent;
  2. argument of speak method should be of type SpeechSynthesisUtterance;
  3. you have messed up the quote marks.

Corrected code:

<body onclick="confirm(this.textContent)?speechSynthesis.speak(new SpeechSynthesisUtterance(this.textContent)):'';">
    Good morning!
</body>
1 Like

Thank you! But it still cannot work in firefox.