Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Богдан Пархоменко
- /*Программа возвращает одну из N тем случайным образом,
- и потом эту тему отдавать какому-то человеку
- */
- function getRandomInt(max) {
- return Math.floor(Math.random() * max);
- }
- var text = [];
- for (let i = 0, a = 1; a != 0; i++) {
- console.log("Ведите тему " + (text.length + 1) + ": ")
- a = prompt("Ведите тему (что бы закончить ввод нажмите 0) " + (text.length + 1) + ": ")
- if (a == 0) {
- break;
- }
- text[i] = a;
- }
- console.log("\n")
- for (let i = 0; i < text.length; i++) {
- console.log(text[i])
- }
- console.log("\n")
- var people = [];
- for (let i = 0, a = 1; a != 0; i++) {
- console.log("Ведите имя человека " + (people.length + 1) + ": ")
- a = prompt("Ведите имя человека (что бы закончить ввод нажмите 0): " + (people.length + 1) + ": ")
- if (a == 0) {
- break;
- }
- people[i] = a;
- }
- console.log("\n")
- for (let i = 0; i < people.length; i++) {
- console.log(people[i])
- }
- console.log("\n\n\n")
- if (text.length >= people.length) {
- for (let c = (people.length), a = 0, b = 0; c != 0;) {
- a = getRandomInt(text.length)
- b = getRandomInt(people.length)
- if (people[b] != 0) {
- console.log(text[a] + " - " + people[b] + "\n")
- console.log()
- people[b] = 0
- c--;
- }
- }
- } else {
- for (let c = (people.length), t = 0, a = 0, b = 0; c != 0; a++) {
- // a = getRandomInt(text.length)
- b = getRandomInt(people.length)
- if (t == 1) {
- a = getRandomInt(text.length)
- }
- if (people[b] != 0) {
- console.log(text[a] + " - " + people[b] + "\n")
- console.log()
- people[b] = 0
- c--;
- }
- if (a == text.length - 1) {
- t = 1;
- }
- }
- }
- console.log("\n\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement