我有一个用于学校翻译项目的按钮组,但我无法让我的按钮工作



var EnglishDictionary = ["Pants", "Pencil Sharpener", "Lampshade", "Pillow", "Hat", "Speaker", "Blueberry", "Strawberry", "Banana", "Starfruit", "Apple", "Mango", "Peach", "Where am I?", "How are you?", "Hello, Whats your name?", "Where is the bathrooom?", "How do I get Home?", "Where is the Resturaunt?"];
var DutchDictionary = ["overhemd", "broek", "puntenslijper", "lampschaduw", "hoofdkussen", "hoed", "spreker", "Bosbes", "Aardbei", "banaan", "stervrucht", "appel", "Mango", "Perzik", "waar ben ik?", "hoe gaat het met je?", "Hallo hoe heet je?", "Waar is de badkamer?", "Hoe kom ik thuis?", "Waar is het toilet?"];
var wordImages = ["Pants.jpg", "Pencil Sharpener.jpg", "Lampshade.jpg", "Pillow.jpg", "Hat.jpg", "Speaker.jpg", "Blueberry.jpg", "Strawberry.jpg", "Banana.jpg", "Starfruit.jpg", "Apple.jpg", "Mango.jpg", "Peach.jpg", "Where am I.jpg", "How are you.jpg", "Hello, What is your name.jpg", "Where is the Bathroom.jpg", "How do I get home.jpg", "Where is the Resturaunt.jpg"];
var wordIndex;
var translatedWord;
var selectedImage;
var displayImage;
var findWord;
var findImage;
function translateWord(word) {
  translatedWord = findWord(word);
  selectedImage = findImage(word);
  document.getElementById("output").value += " " + translatedWord;
  displayImage = document.getElementById("displayImages").checked;
  if (displayImage == true) {
    document.getElementById("image").src = selectedImage;
  }
}
function findWord(word) {
  for (wordIndex in EnglishDictionary) {
    if (word == EnglishDictionary[wordIndex]) {
      return DutchDictionary[wordIndex];
    }
  }
}
function findImage(word) {
  for (wordIndex in EnglishDictionary) {
    if (word == EnglishDictionary[wordIndex]) {
      return wordImages[wordIndex];
    }
  }
}
<button onclick="translateWord('Pillow')" class="button">Pillow</button>
<input type="text" id="output">
<input type="checkbox" id="displayImages">
<img id="image" src="" />

这是我的按钮组的javascript,但是当我按下按钮时没有任何效果,我一直得到

未捕获的引用错误:未定义翻译单词

这是什么意思,我该如何解决。 谢谢。这是针对学校项目。

你的脚本标签有一个拼写错误"javasript"。 它应该是JavaScript

<script type="text/javascript">
var EnglishDictionary = ["Pants","Pencil Sharpener","Lampshade","Pillow","Hat","Speaker","Blueberry","Strawberry","Banana","Starfruit","Apple","Mango","Peach","Where am I?","How are you?","Hello, Whats your name?","Where is the bathrooom?","How do I get Home?","Where is the Resturaunt?"];
var DutchDictionary = ["overhemd","broek","puntenslijper","lampschaduw","hoofdkussen","hoed","spreker","Bosbes","Aardbei","banaan","stervrucht","appel","Mango","Perzik","waar ben ik?","hoe gaat het met je?","Hallo hoe heet je?","Waar is de badkamer?","Hoe kom ik thuis?","Waar is het toilet?"];
var wordImages = ["Pants.jpg","Pencil Sharpener.jpg","Lampshade.jpg","Pillow.jpg","Hat.jpg","Speaker.jpg","Blueberry.jpg","Strawberry.jpg","Banana.jpg","Starfruit.jpg","Apple.jpg","Mango.jpg","Peach.jpg","Where am I.jpg","How are you.jpg","Hello, What is your name.jpg","Where is the Bathroom.jpg","How do I get home.jpg","Where is the Resturaunt.jpg"];
var wordIndex;
var translatedWord;
var selectedImage;
var displayImage;
var findWord;
var findImage;
function translateWord(word) 
{ alert(2)
    translatedWord = findWord(word);
    selectedImage = findImage(word);
    document.getElementById("output").value += " " + translatedWord;
    displayImage = document.getElementById("displayImages").checked;
    if (displayImage == true) 
    {
        document.getElementById("image").src = selectedImage;
    }   
}

function findWord(word) 
{
    for (wordIndex in EnglishDictionary)
    {
        if (word == EnglishDictionary[wordIndex])
        {
            return DutchDictionary[wordIndex]; 
        }
    }               
}

function findImage(word) 
{
    for (wordIndex in EnglishDictionary)
    {
        if (word == EnglishDictionary[wordIndex])
        {
            return wordImages[wordIndex]; 
        }
    }               
}
</script>
 <button onclick= "translateWord('Pillow')" class="button">Pillow</button> 

最新更新