简体   繁体   English

收到“意外令牌错误”

[英]Getting an “Unexpected Token Error”

I am supposed to make a program that predicts the winners of March Madness games and I keep getting an "Unexpected token error" and I cannot find where the error in the syntax is. 我应该编写一个预测三月疯狂游戏获胜者的程序,并且不断收到“意外的令牌错误”,而且找不到语法错误在哪里。 I'm a novice so any help is appreciated thanks! 我是新手,因此感谢您的任何帮助! (Also if you could tell me how to more easily find my errors without asking for help in the future that would help me greatly!) (此外,如果您能告诉我如何更轻松地发现我的错误,而无需在将来寻求帮助的话,那将对我有很大帮助!)

/*Asks users for the Offensive and defensive efficiencies of each team,
and asks for their seed in the tournament*/

var team1 = {
offEff: prompt("Offensive Efficency for Team 1", "ex 1.28"),
defEff: prompt("Defensive Efficency for Team 1", "ex .72"),
seed: prompt("Seed for Team 1", "ex 2")
};
var team2 = {
offEff: prompt("Offensive Efficency for Team 2", "ex 1.28"),
defEff: prompt("Defensive Efficency for Team 2", "ex .72"),
seed: prompt("Seed for Team 2", "ex 2")
};

/*This function adds point values to each team based on comparisons
in each category, and whoever's point value is highest is printed
to the console.*/

function (team1, team2)
{
var team1p = 0;
var team2p = 0;

if (team1.seed < team2.seed)
    team1p+=3;
else
    team2p+=3;

if(team1.offEff > team2.offEff)
    team1p+=1.5;
else
    team2p+=1.5;

if(team1.defEff < team2.defEff)
    team1p+=1.5;
else
    team2p+=1.5;

if (team1p >= team2p) 
    console.log("Team 1 will win!");
else 
    console.log("Team 2 will win!");

};

give some function name to the function and call it 给该函数指定一些函数名称并调用它

 var team1data = {
    offEff: prompt("Offensive Efficency for Team 1", "ex 1.28"),
    defEff: prompt("Defensive Efficency for Team 1", "ex .72"),
    seed: prompt("Seed for Team 1", "ex 2")
    };
    var team2data = {
    offEff: prompt("Offensive Efficency for Team 2", "ex 1.28"),
    defEff: prompt("Defensive Efficency for Team 2", "ex .72"),
    seed: prompt("Seed for Team 2", "ex 2")
    };



    function funcname(team1, team2)
    {
    var team1p = 0;
    var team2p = 0;

    if (team1.seed < team2.seed)
        team1p+=3;
    else
        team2p+=3;

    if(team1.offEff > team2.offEff)
        team1p+=1.5;
    else
        team2p+=1.5;

    if(team1.defEff < team2.defEff)
        team1p+=1.5;
    else
        team2p+=1.5;

    if (team1p >= team2p) 
        console.log("Team 1 will win!");
    else 
        console.log("Team 2 will win!");

    };
    funcname(team1data ,team2data );

 /*Asks users for the Offensive and defensive efficiencies of each team, and asks for their seed in the tournament*/ var team1 = { offEff: prompt("Offensive Efficency for Team 1", "ex 1.28"), defEff: prompt("Defensive Efficency for Team 1", "ex .72"), seed: prompt("Seed for Team 1", "ex 2") }; var team2 = { offEff: prompt("Offensive Efficency for Team 2", "ex 1.28"), defEff: prompt("Defensive Efficency for Team 2", "ex .72"), seed: prompt("Seed for Team 2", "ex 2") }; /*This function adds point values to each team based on comparisons in each category, and whoever's point value is highest is printed to the console.*/ function WhichTeamWon(team1, team2) { var team1p = 0; var team2p = 0; if (team1.seed < team2.seed) team1p+=3; else team2p+=3; if(team1.offEff > team2.offEff) team1p+=1.5; else team2p+=1.5; if(team1.defEff < team2.defEff) team1p+=1.5; else team2p+=1.5; if (team1p >= team2p) console.log("Team 1 will win!"); else console.log("Team 2 will win!"); }; WhichTeamWon(team1, team2); 

If you don't want to name your function, or don't want to use it elsewhere, you can use the immediately invoked function expression: 如果您不想命名函数,或者不想在其他地方使用它,则可以使用immediately invoked function表达式:

var team1 = {
    //..
};
var team2 = {
    //..
};


(function (team1, team2) {
    //
    // ...
    //
}(team1, team2));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM