2017-10-04 13 views
-1

ランダムに背景の色と引用符の内容を変更するための2つの関数を書きました。次に、これらの機能を実行するためのボタンをクリックしました。 色の変更に成功しましたが、引用符は表示されず、両方の機能がプログラム上にあるときにも色は変わりません。 私のコードで何が問題になっていますか?引用符の色や内容が表示されない

<!DOCTYPE HTML> 
<html> 




<head> 
<meta charset="UTF-8"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<!-- let's get started --> 
<title>Random Quote</title> 

<!-- //******CSS********************// --> 
<style> 
    .Container{ 
    height:100%; 

    display:grid; 

    background-color:white; 
    } 
</style> 
<!-- //******JavaScript************// --> 
<script> 
function randColor() { 
    var letters = 'ABCDEF'.split(''); 
    var color = '#'; 
    for (var i = 0; i < 6; i++) {color += letters[Math.round(Math.random() * 15)]; 
    } 
    if(color=="#000000"){ // to exclude white from brower background color since the color of the 'Container' is always white  
    color[2]=color[2]+1; 
    document.body.style.backgroundColor = color;} 
    else 
    document.body.style.backgroundColor = color;  
} 

function randQuote(){ 
    var randNum= Math.floor(Math.random()*10) ; 
    var quote=[ 
    "You can do anything, but not everything. —David Allen", 
    "Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.—Antoine de Saint-Exupéry", 
    "The richest man is not he who has the most,but he who needs the least. —Unknown Author", 
    "You miss 100 percent of the shots you never take. —Wayne Gretzky", 
    "You must be the change you wish to see in the world. —Gandhi", 
    "We are what we repeatedly do. excellence, then, is not an act but a habit.—Aristotle" 
    "A wise man gets more use from his enemies than a fool from his friends.—Baltasar Gracian", 
    "What we think, or what we know, or what we believe is, in the end, of little consequence. The only consequence is what we do.—John Ruskin", 
    "The real voyage of discovery consists not in seeking new lands but seeing with new eyes.—Marcel Proust", 
    "Don\’t ever wrestle with a pig. You’ll both get dirty, but the pig will enjoy it.—Cale Yarborough" 
    ]; 

    document.getElementById("ShowQuote").innerHTML=quote[randNum]; 
} 

</script> 
</head> 

<!-- //******HTML******************// --> 
<body> 

<div class="Container"> 
    <div id="ShowQuote"> 

    </div> 

    <button class="btn" onclick="randQuote();randColor()">New Quote</button> 





</div> 

</body> 




</html> 
+0

あなたのHTMLは無効です。バリデーターを通してあなたのHTMLを実行し、最初にエラーを修正してください。 – Rob

+0

ありがとう、私はそれを解決しましたが、まだその2つの機能をアクティブにする方法を知らない。 –

答えて

0

46行目にコンマがありません。ブラウザのコンソールに、開発者ツールのエラーとして表示されます。

Uncaught SyntaxError: Unexpected string

ちょうどその行の末尾にカンマを追加します。

"We are what we repeatedly do. excellence, then, is not an act but a habit.—Aristotle", 
+0

うわー。大変感謝しています。あなたは素晴らしいです。この種のエラーをまだ捕まえるのは簡単ではありません。 –

関連する問題