Показать сообщение отдельно
  #1 (permalink)  
Старый 19.08.2012, 17:14
Аспирант
Отправить личное сообщение для Jeremen Посмотреть профиль Найти все сообщения от Jeremen
 
Регистрация: 03.02.2012
Сообщений: 45

Функция выдает что-то попало, помогите пожалуйста
Вот есть такая структура
<div id="card"></div>

И такой JS
function gameCore() {
			var card = document.getElementById('card');
			var position = {
				top: getRandom(document.documentElement.clientHeight) - 270,
				left: getRandom(document.documentElement.clientWidth) - 320
			};
			var colorsArr = ['yellow', 'orange', 'hotPink', 'red', 'green', 'black', 'deepSkyBlue', 'mediumBlue'];
			var color = colorsArr[Math.floor(Math.random() * colorsArr.length)];
			
			if (color === card.style.backgroundColor) {
				getColorWithoutReps(card.style.backgroundColor);
			}
			
			card.style.backgroundColor = color;
			
			if (position.top < 0) {
				position.top = 250;
			}
			
			if (position.left < 0) {
				position.left = 650;
			}
			
			card.style.top = position.top + 'px';
			card.style.left = position.left + 'px';
			
			function getColorWithoutReps(colorArg) {
				while (color === colorArg) {
					color = colorsArr[Math.floor(Math.random() * colorsArr.length)];
				} 
			}
			
			function getRandom(includingTo) {
			     return Math.floor(Math.random() * includingTo + 1);
			}
			
		}

По задумке есть карточка она прыгает по экрану и всё время меняет цвет, цвет не должен повторяться. Сделал такую функцию но почему-то цвет бывает повторяется. Никак не пойму как-такое может быть помогите пожалуйста...
Ответить с цитированием