Hello, hello! I need some help with JavaScript … π‘
I’m doing a spanish project for school and I decided to write a page that stores the names of the terms (it’s a teaching tool) and the images of those terms in separate arrays. Then later in the document I put in an input where the visitor can type the name of the term when they recognize what the picture displayed represents.
So this is the format:
<picture>
Guess here: <input field> <submit information button>
When the button is pressed, I’m trying to get it to compare the information entered with the index of the picture that’s displayed. If it’s the same, then it alerts the user (Cierto!) and if it’s not, then it alerts the user (Falso!).
I’m having problems and it’s due Monday. I’m begging anyone who knows JS to help me … thanks.
Here’s my code (of course, the picture URL’s are different):
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html>
<head>
<script type=”text/javascript”>
var element_names = new Array(7)
element_names[0] = “linea”
element_names[1] = “color”
element_names[2] = “valor”
element_names[3] = “figura”
element_names[4] = “textura”
element_names[5] = “forma”
element_names[6] = “espacio”
var element_imgs = new Array(7)
element_imgs[0] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[1] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[2] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[3] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[4] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[5] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
element_imgs[6] = “C:Documents and SettingskidsMy DocumentsMy PicturesDeviantARTbridge.jpg”
function check()
{
x=document.input.guess
cierto=x.value.indexOf(switch(imgs))
if (cierto != switch(imgs))
{
alert(“Falso!”)
}
if (cierto == switch(imgs))
{
alert(“Cierto!”)
}
}
</script>
</head>
<body>
<script type=”text/javascript”>
var a=Math.random()*7
var b=(Math.round(a))
var imgs=b
switch (imgs)
{
case 0:
document.write(“<img src=element_imgs[0] />”)
break
case 1:
document.write(“<img src=element_imgs[1] />”)
break
case 2:
document.write(“<img src=element_imgs[2] />”)
break
case 3:
document.write(“<img src=element_imgs[3] />”)
break
case 4:
document.write(“<img src=element_imgs[4] />”)
break
case 5:
document.write(“<img src=element_imgs[5] />”)
break
case 6:
document.write(“<img src=element_imgs[6] />”)
break
}
</script>
Input guess here (remember that spelling counts, ignore accents):
<input type=”text” name=”guess” size=”20″>
<input type=”button” value=”Check!” onclick=”return check()” />
</body>
</html>