Javascript 为什么我的JS函数在Chrome开发控制台中不返回任何结果?

Javascript 为什么我的JS函数在Chrome开发控制台中不返回任何结果?,javascript,html,function,Javascript,Html,Function,我的函数compPlay()在控制台中不返回任何结果。我有写的函数,我相信是正确的语法和正确使用“数学随机”和“数学”地板。请帮帮我 <!doctype html> <html lang="en-us"> <head> <meta charset="UTF-8"> <title>Rock Paper Scissor Game</title> <!--

我的函数compPlay()在控制台中不返回任何结果。我有写的函数,我相信是正确的语法和正确使用“数学随机”和“数学”地板。请帮帮我

 <!doctype html>
    <html lang="en-us">

    <head>
        <meta charset="UTF-8">
        <title>Rock Paper Scissor Game</title>
        <!-- CSS, STYLESHEET -->
        <link rel="stylesheet" type="text/css" href="assets/css/style2.css">
        <!-- BOOTSTRAP -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
        <!-- JQUERY, 3.2.1 -->
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">

            function compPlay {
                const choices = ["rock", "paper", "scissors"]
                return choices([Math.floor(Math.random() * choice.length)];
            }

石头剪纸游戏
函数compPlay{
常量选项=[“石头”、“布”、“剪刀”]
返回选项([Math.floor(Math.random()*choice.length)];
}

脚本标记之间似乎不包含compPlay函数。 使用此功能,您的功能应该可以在浏览器控制台上正常工作


函数compPlay(){
常量选项=[“石头”、“布”、“剪刀”]
返回选项([Math.floor(Math.random()*choices.length)];
}

在您的代码中,SULLAY未定义为方法

与此相反:

function compPlay {
            const choices = ["rock", "paper", "scissors"]
            return choices([Math.floor(Math.random() * choice.length)];
        }
试试这个:

function compPlay() {
    const choices = ["rock", "paper", "scissors"];
    return choices[Math.floor(Math.random() * choice.length)];
}

script
标记可能包含
src
属性或内部定义的代码。如果它同时包含这两个代码,则忽略它。更正后,您将看到代码中的所有语法错误

console.log(compPlay());

函数compPlay(){
常量选项=[“石头”、“布”、“剪刀”]
返回选项[Math.floor(Math.random()*choices.length)];
}

缺少括号
函数compPlay(){
此外,请注意错误的“(
之后返回选项
选项中缺少的“s”。长度
选项不是function@Igor抱歉,伙计,谢谢你纠正我。