A
A
Arthur A.2017-09-26 21:18:56
JavaScript
Arthur A., 2017-09-26 21:18:56

Combine two identical scripts into one, how?

Need to make the second number work
https://jsfiddle.net/enp6a2zd/
Ps. thanks in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2019-06-15
@sergiks

In the current version

your code
// Функция получения случайного числа
const getRandomNumber = (() => {
  return Math.floor(Math.random() * 1000);
});

// Функция получения случайного имени
const getRandomName = (() => {
  const arr = ['Alex', 'Bob', 'Mark', 'Peter'];
  let randomNumber = Math.floor(Math.random() * arr.length);
  return arr[randomNumber];
});

// Начальный объект
const obj = {
  name: getRandomName(),
  id: getRandomNumber()
};

// 1.2 Добавление нового поля в объект
obj.number = getRandomNumber();

const randomArray = () => Array(6).fill().map(() => obj);
console.log(randomArray());
value repetition is not excluded: the same “random” number from the range can easily fall out. 0..999To prevent repeated values, you can create an array with possible values, and take it out of it - this way the absence of repetitions is guaranteed. The object is now created only once, and the same one is nested in the array. Maybe it's easier to do it in a loop? Array.splice(i, 1)
Array.push()

V
Vladimir Skibin, 2017-09-26
@megafax

https://jsfiddle.net/enp6a2zd/71/
Use relative find elements

A
Arthur A., 2017-09-26
@dokxpi

Thank you very much Is
it possible to send clicks on the second number to kuzn_t03?
.. on the first number, clicks go to kuzn_t02
https://jsfiddle.net/enp6a2zd/71/

// яндекс
$('.sh_num').click(function(){
  yaCounter43664069.reachGoal('kuzn_t02'); 
  
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question