<script>
function getRandom() {
this.randomNum = function(min,max){
let random = Math.random()*(max-min)+min
return Math.round(random)
}
}
let r1 = new getRandom()
let r2 = r1.randomNum(1,10)
console.log(r2)
let num;
do {
num = +prompt('请输入任意数字:')
if (num > r2) {
alert('你猜大了')
}else if (num < r2){
alert('你猜小了');
}
} while (num != r2);
console.log(`恭喜你,猜对了`);
</script>
<script>
let arr = ['鹿晗','王俊凯','蔡徐坤','彭于晏','周杰伦','刘德华','赵本山'];
let newarr = new Array()
for (let j = 0; newarr.length < 4; j++) {
let num = Math.floor(Math.random()*7)
if (newarr.lastIndexOf(arr[num])===-1) {
newarr.unshift(arr[num])//从首部插入元素
}
}
console.log(newarr)
</script>
3.题目描述:使用Math对象,制作一个16进制的随机颜色。题目提示:16进制包括‘ 0 1 2 3 4 5 6 7 8 9 A B C D E F’,例:”#f23a4b”
<script>
function getColor() {
var arr = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E'