javascript Uncaught SyntaxError: expected expression, got ')'。[非公开]

问题描述 投票:-2回答:2

我在做我的第一个javascript代码,我得到了这个错误。我不知道为什么会这样。这个错误是在第一行和最后一行,这是它说的。导致这个错误,大部分的代码不工作。请帮助

代码有点长,我不能发问题。这就是为什么我写了这行完全没用的代码。

下面是完整的代码。

document.addEventListener('DOMContentLoaded',function(){
const catbutton=document.getElementById('catbutton');
const cubebutton=document.getElementById('cubebutton');
const image=document.getElementById('image');
const puntuation=document.getElementById('puntuation');
const puntuator=document.getElementById('puntuator');
const pantplay=document.getElementById('pantplay');
const pantprincipal=document.getElementById('pantalla-principal');
const closepunt=document.getElementById('accionador');
const playbutton=document.GetElemendById('playbutton');
function closepuntuation(){
    puntuator.style="display: none";
    pantplay.style="display: none";
    pantprincipal.style="display: ";
    x=0;
}
var timeoutID;
playbutton.onclick=function(){timestart()}
function timestart() {
  timeoutID = setTimeout(function(){pantplay.style="display: none";
        puntuator.style="display: ";
        puntuation.innerHTML=x;
        closepunt.onclick=function() {closepuntuation()};}, 2*1000);
}
catbutton.onclick=function(){timecancel()}
cubebutton.onclick=function(){timecancel()}
function timecancel() {
  clearTimeout(timeoutID);
var x=0;
var arr= ["cat1.jpg", "cat2.jpg", "cat3.jpg", "cat4.jpg", "cat5.jpg", "cat6.jpg", "cat7.jpg", "cat8.jpg", "cat9.jpg","cube1.jpg", "cube2.jpg", "cube3.jpg", "cube4.jpg", "cube5.jpg", "cube6.jpg", "cube7.jpg", "cube8.jpg"];
let randomElement = arr[Math.floor(Math.random() * arr.length)];
console.log(randomElement);
image.src=(randomElement);
catbutton.onclick=function(){catfunction()};
function catfunction(){
    if (randomElement=="cat1.jpg" || randomElement=="cat2.jpg" || randomElement=="cat3.jpg" || randomElement=="cat4.jpg" || randomElement=="cat5.jpg" || randomElement=="cat6.jpg" || randomElement=="cat7.jpg" || randomElement=="cat8.jpg" || randomElement=="cat9.jpg"){
        x++;
        randomElement = arr[Math.floor(Math.random() * arr.length)];
        console.log(randomElement);
        console.log(randomElement);
        image.src=(randomElement);
    }
    else{
        pantplay.style="display: none";
        puntuator.style="display: ";
        puntuation.innerHTML=x;
        closepunt.onclick=function(){closepuntuation()};
    }
}
cubebutton.onclick=function(){cubefunction()};
function cubefunction(){
    if (randomElement=="cube1.jpg" || randomElement=="cube2.jpg" || randomElement=="cube3.jpg" || randomElement=="cube4.jpg" || randomElement=="cube5.jpg" || randomElement=="cube6.jpg" || randomElement=="cube7.jpg" || randomElement=="cube8.jpg"){
        x++;
        randomElement = arr[Math.floor(Math.random() * arr.length)];
        console.log(randomElement);
        console.log(randomElement);
        image.src=(randomElement);
    }
    else{
        pantplay.style="display: none";
        puntuator.style="display: ";
        puntuation.innerHTML=x;
        closepunt.onclick=function() {closepuntuation()};
    }
}
});
javascript html syntax
2个回答
0
投票

function timecancel() { 没有收尾括号,需要一个。

当你遇到这样的错误时,你需要仔细确认你的括号和大括号是否匹配。许多编辑器可以帮助你解决这个问题,但大多数时候还是要靠你自己小心。一般来说,这样的问题不适合在StackOverflow上讨论,但我知道你是语言新手。

© www.soinside.com 2019 - 2024. All rights reserved.