2017-08-12 10 views
0

私はメカニックのウェブサイト用のJavaScriptフラッシュカードゲームを作っています。カードに方程式を入れたいので、デルタ(Δ)記号を使う必要があります。デルタ記号が壊れているJavaScriptコード

カードには、一方の「力の式」と他方の「P = W /Δt」があります。カードがサイド1から始まる場合、スペースキーが押されたとき、またはフリップボタンが押されたときに反転します。ただし、2桁目から開始する場合は、「△」記号付きのフリップボタンまたはスペースキーが押されたときに反転しません。これら働いていたの

Δ Δ Δ 

なし:

私は別の書き込みΔの方法を試してみました。 私のコードは次のとおりです。

//Copyright Attribution-ShareAlike 4.0 International 2017 Hazel Meehan 
 

 

 
//array containing all options 
 
var options = [ //counts from 0 
 
    "Joules(J)", "Measure of Work", 
 
    "Watts(W)", "Measure of Power", 
 
    "Ek", "Kinetic Energy", 
 
    "Ep", "Potential Energy", 
 
    "Newtons(N)", "Measure of Force", 
 
    "Pascals(Pa)", "Pressure", 
 
    "ms-1", "Metres per Second", 
 
    "ms-2", "Metres per Second Gained", 
 
    "10N", "Value of Gravity", 
 
    "Weight is a", "Force beginning with W", 
 
    "The capacity to do work", "Energy is", 
 
    "d = ΔvΔt is the equation for", "The equation for distance", 
 
    "W=FΔd is the equation for", "The equation for work", 
 
    "P=W/Δt is the equation for", "The equation for power" 
 
]; 
 

 
//initialize variables 
 
var randomNum = 0; 
 
var sideOne = " "; 
 
var sideTwo = " "; 
 

 
//choose new card using random number 
 
var newCard = function() { //runs on 'next' 
 
    var randomNum = Math.floor(Math.random() * options.length); 
 
    sideOne = options[randomNum]; 
 
    if (randomNum % 2 == 0) { //is the number even 
 
    sideTwo = options[randomNum + 1]; 
 
    } else { 
 
    sideTwo = options[randomNum - 1]; 
 
    } 
 
    document.getElementById("card").innerHTML = sideOne; 
 
}; 
 

 
//show other side of card 
 
var flip = function() { //runs on 'flip' 
 
    if (document.getElementById("card").innerHTML == sideOne) { 
 
    document.getElementById("card").innerHTML = sideTwo; 
 
    } else { 
 
    document.getElementById("card").innerHTML = sideOne; 
 
    } 
 
}; 
 

 
//change card on key down 
 
document.onkeydown = function(e) { 
 
    e = e || window.event; 
 
    if (e.keyCode == '39') { //right arow key 
 
    newCard(); 
 
    } else if (e.keyCode == '32') { //space bar 
 
    flip(); 
 
    } 
 
}
<article> 
 
    <h2>Flashcards</h2> 
 
    <center><button id="flashButton" onclick="newCard()">Next</button></center> 
 
    <br> 
 
    <center><button id="card"></button></center> 
 
    <br> 
 
    <center><button id="flashButton" onclick="flip()">Flip</button></center> 
 
</article>

+1

ここで[SO](https://stackoverflow.com)で作業していますので、HTMLタグに 'タグを追加してください。 –

+0

私のために働く。どのブラウザを使用していますか?コンソールにログインしているものは何ですか? – marekful

+0

バグを再現することができます。「Δ」を「Δ」に置き換えると消えてしまいます。 – ASDFGerte

答えて

1

チェックする要素のinnerHtmlif (document.getElementById("card").innerHTML == sideOne))、あらかじめ設定された文字列をHTMLとして解釈されてきたし、それを取得する際に、&Delta;は今Δになります。比較は、偽です:

"d = &Delta;v&Delta;t is the equation for" !== "d = ΔvΔt is the equation for"

したがって、それは再び同じ側にinnerHtmlを設定します。

関連する問題