2017-10-04 7 views
-1

J'ai écrit deux fonctions pour changer la couleur de l'arrière-plan au hasard et le contenu des citations aussi. Ensuite, j'ai fait un bouton pour effectuer ces fonctions lorsque l'on clique dessus. J'ai réussi à changer la couleur mais les guillemets n'apparaîtront pas et quand les deux fonctions sont sur le programme, la couleur ne changera pas aussi. Quel est le problème avec mon code?Couleur ou le contenu des citations ne montre pas

<!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

Votre code HTML est invalide. Exécutez votre code HTML via le validateur et corrigez d'abord vos erreurs. – Rob

+0

Merci, je l'ai réparé mais je ne sais toujours pas comment activer ces 2 fonctions. –

Répondre

0

Il vous manque une virgule sur la ligne 46. Cela apparaît dans la console de votre navigateur comme une erreur dans les outils de développement.

Uncaught SyntaxError: Unexpected string

Il suffit d'ajouter une virgule à la fin de cette ligne:

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

wow cela a fonctionné. merci un million de Rob. tu es incroyable. Ce n'est pas facile pour moi d'attraper ce genre d'erreurs pour le moment. –