2017-10-04 1 views
-1

배경색을 임의로 변경하고 따옴표의 내용을 변경하는 두 가지 기능을 작성했습니다. 그런 다음이 기능을 수행하기 위해 버튼을 클릭했습니다. 색상 변경에 성공했지만 따옴표가 나타나지 않으며 두 기능이 모두 프로그램에 있으면 색상이 변경되지 않습니다. 내 코드에 어떤 문제가 있습니까?따옴표의 색이나 내용이 표시되지 않음

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

고마워, 나는 그것을 고쳤지 만 여전히 그 두 가지 기능을 활성화하는 방법을 모르겠다. –

답변

0

46 행에 쉼표가 누락되었습니다. 개발자 도구에서 브라우저의 콘솔에 오류로 표시됩니다.

Uncaught SyntaxError: Unexpected string

그냥 그 줄의 끝에 쉼표를 추가

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

와우 효과가 있습니다. 고마워요. Rob. 당신 정말 대단하네요. 아직 이런 종류의 오류를 잡기 란 쉽지 않습니다. –

관련 문제