Javaspric
1``````(function(){ 2 'use strict'; 3 var btn = document.getElementById('btn'); 4 btn.addEventListener('click', function(){ 5 var n = Math.random(); 6 if(n < 0.9){ 7 this.textContent = 'あ'; 8 } 9 else if (n < 0.9){ 10 this.textContent = 'い'; 11 } 12 else if (n < 0.9){ 13 this.textContent = 'う'; 14 } 15 else if (n < 0.9){ 16 this.textContent = 'え'; 17 } 18 else if (n < 0.9){ 19 this.textContent = 'お'; 20 } 21 else if (n < 0.9){ 22 this.textContent = 'か'; 23 } 24 else if (n < 0.9){ 25 this.textContent = 'き'; 26 } 27 else if (n < 0.9){ 28 this.textContent = 'く'; 29 } 30 else if (n < 0.9{ 31 this.textContent = 'け'; 32 }else{ 33 this.textContent = 'こ'; 34 } 35 }); 36 btn.addEventListener('mousedown', function(){ 37 this.className = 'pushed'; 38 }); 39 btn.addEventListener('mouseup', function(){ 40 this.className = ''; 41 }); 42})(); 43コード 44
```html <html lang="ja"> <head> <meta charset="utf-8"> <title>おみくじ</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id = "btn">push!</div> <script src=random.js></script> </body> </html>ここに言語を入力 コード
エラーが出てしまってます
イメージとしてはプッシュを押すとアからコをランダムで出したいです
random.js:5 Uncaught TypeError: Cannot read property 'addEventListener' of null
at random.js:5
at Object../app/javascript/random.js (random.js:49)
at webpack_require (bootstrap:19)
at Object../app/javascript/packs/application.js (application.js:10)
at webpack_require (bootstrap:19)
at bootstrap:83
at bootstrap:83
回答2件
あなたの回答
tips
プレビュー