1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <script> function color() { var arrNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f']
var newArr = arrNum.join(''); console.log(newArr); console.log(newArr.length); var str = '#'; for (var i = 0; i < 6; i++) { var j = Math.floor(Math.random() * arrNum.length); str += newArr[j] } console.log(str); } color()
function getColor() {
var str = '#';
var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
for (var i = 0; i < 6; i++) { var num = parseInt(Math.random() * 16); arr[num]; str += arr[num]; } return str; } console.log(getColor()); </script>
|