0
HTMLページ内にファイルからカードを表示したい。私は2つの配列から2つのランダムに選択された値を取得しようとしていますし、それらを一緒にして画像のsrcを作成しています。2つの変数を使用してJavaScriptから画像を表示する
キャッチされない例外TypeError:blackJack.jsでヌル のプロパティ 'SRC' を設定することはできません:14
HTMLコード
<!DOCTYPE html>
<html lang ='en'>
<head>
<meta charset="UTF-8">
<script src="blackJack.js"></script>
<title>Section 2: Javascript Language Basics</title>
</head>
<body>
<h1>Section 2: Javascript Language Basics</h1>
<img id="myImg" src="/Users/victorcollins/Desktop/Computer Science/IA/Coding/Playing Cards/PNG-cards-1.3/2spades.png" width="107" height="98">
</body>
</html>
Javascriptを
私はこれをしようとすると、私はこのエラーを取得しておきますvar suits, cards, players, randCards, randSuit;
suits = ['hearts', 'diamonds', 'spades', 'clubs'];
cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
players = [];
randCards = Math.floor(Math.random() * 13) + 1;
var randSuit = suits[Math.floor(Math.random() * suits.length)];
image = randCards + randSuit;
console.log(randCards+randSuit);
console.log(image);
document.getElementById("myImg").src = '/Users/victorcollins/Desktop/Computer Science/IA/Coding/Playing Cards/PNG-cards-1.3'+image+'.png';
このHTMLは無効です。 '