Javascript蛇游戏不起作用

Javascript蛇游戏不起作用,javascript,html,canvas,Javascript,Html,Canvas,我的代码怎么了?我的蛇不像书中的代码那样工作。这段代码是为尼克·摩根(Nick Morgan)的优秀著作《儿童JavaScript》编写的。我从书中下载了代码,它似乎和我的一样,我是不是遗漏了什么 请参见此处的JSFIDLE: http://jsfiddle.net/raenset/ehjyt08k/ 代码: var canvas=document.getElementById(“canvas”); var ctx=canvas.getContext(“2d”); var width=canv

我的代码怎么了?我的蛇不像书中的代码那样工作。这段代码是为尼克·摩根(Nick Morgan)的优秀著作《儿童JavaScript》编写的。我从书中下载了代码,它似乎和我的一样,我是不是遗漏了什么

请参见此处的JSFIDLE:

http://jsfiddle.net/raenset/ehjyt08k/
代码:
var canvas=document.getElementById(“canvas”);
var ctx=canvas.getContext(“2d”);
var width=canvas.width;
var height=canvas.height;
var块大小=10;
var widthInBlocks=宽度/块大小;
var heightInBlocks=高度/块大小;
var得分=0;
var drawBorder=函数(){
ctx.fillStyle=“灰色”;
ctx.fillRect(0,0,宽度,块大小);
ctx.fillRect(0,高度-块大小,宽度,块大小);
ctx.fillRect(0,0,块大小,高度);
ctx.fillRect(宽度-块大小,0,块大小,高度);
};
var drawScore=函数(){
ctx.font=“20px快递”;
ctx.fillStyle=“黑色”;
ctx.textAlign=“左”;
ctx.textb基线=“顶部”;
ctx.fillText(“分数:+分数,块大小,块大小);
};
var gameOver=函数(){
clearInterval(intervalId);
ctx.font=“60px快递”;
ctx.fillStyle=“黑色”;
ctx.textAlign=“中心”;
ctx.textb基线=“中间”;
ctx.fillText(“游戏结束”,宽度/2,高度/2);
};
变量圆=函数(x、y、半径、圆角圆){
ctx.beginPath();
弧(x,y,半径,0,数学π*2,假);
如果(填充圆){
ctx.fill();
}
否则{
ctx.stroke();
}
};
var块=函数(列,行){
this.col=col;
this.row=行;
};
Block.prototype.drawSquare=函数(颜色){
var x=this.col*块大小;
var y=this.col*块大小;
ctx.fillStyle=颜色;
ctx.fillRect(x,y,blockSize,blockSize);
};
Block.prototype.drawCircle=函数(颜色){
var centerX=this.col*blockSize+blockSize/2;
var centerY=this.row*blockSize+blockSize/2;
ctx.fillStyle=颜色;
圆(centerX、centerY、块大小/2,真值);
};
Block.prototype.equal=函数(其他块){
返回this.col===otherBlock.col&&this.row===otherBlock.row;
};
var Snake=函数(){
此值为0.1段=[
新大厦(7,5),,
新大楼(6,5),
新大厦(5,5)
];
this.direction=“right”;
this.nextDirection=“right”;
};
Snake.prototype.draw=函数(){
对于(var i=0;i

从JSFIDLE脚本区域的顶行删除标记,代码就会正常工作。JSFIDLE不喜欢脚本区域内的脚本标记

PS这也是我的html:
code
Snake<代码>代码
在你的小提琴中,如果你在JavaScript代码的开头删除“”部分,它会运行。当然,但我希望它作为“蛇游戏”运行,而不是像现在这样。