请在提供的html文件基础上编写JavaScript代码,实现以下功能:每次单击页面上的盒子时,随机切换盒子的背景颜色(供选择的颜色有:红色:red、蓝色:blue、黄色:yellow、绿色:green、紫色:purple),并在盒子中显示自己的班级+姓名;双击页面上的盒子时,盒子恢复成默认颜色。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
#box {
width: 300px;
height: 300px;
background-color: #999;
}
</style>
</head>
<body>
<div id="box">班级 姓名</div>
<script type="text/javascript">
var box = document.getElementById("box");
var arr = ["red","blue","yellow","green","purple"];
box.onclick = function(){
var n = Math.floor(Math.random()*arr.length);
box.style.backgroundColor = arr[n];
}
box.ondblclick = function(){
box.style.backgroundColor = "";
}
</script>
</body>
</html>