Advertisement
dimipan80

Digital Soothsayer

Nov 9th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Write a JavaScript function soothsayer(numsArr, langsArr, citiesArr, carsArr) that accepts
  2.  the following parameters (source arrays): array of numbers, array of programming languages,
  3.  array of cities, array of cars. Each array must consist of five elements.
  4.  The function must return an array result[] that consists of one random item from each source array.
  5.  Write a JS program that prints on the console the following output:
  6.  “You will work result[0] years on result[1]. You will live in result[2] and drive result[3].”.  */
  7.  
  8. "use strict";
  9.  
  10. function soothsayer(numsArr, langsArr, citiesArr, carsArr) {
  11.     return [numsArr[parseInt(Math.random() * numsArr.length)],
  12.         langsArr[parseInt(Math.random() * langsArr.length)],
  13.         citiesArr[parseInt(Math.random() * citiesArr.length)],
  14.         carsArr[parseInt(Math.random() * carsArr.length)]];
  15. }
  16.  
  17. var result = soothsayer([3, 5, 2, 7, 9],
  18.     ['Java', 'Python', 'C#', 'JavaScript', 'Ruby'],
  19.     ['Silicon Valley', 'London', 'Las Vegas', 'Paris', 'Sofia'],
  20.     ['BMW', 'Audi', 'Lada', 'Skoda', 'Opel']);
  21.  
  22. console.log('You will work ' + result[0] + ' years on ' + result[1]
  23. + '. You will live in ' + result[2] + ' and drive ' + result[3] + '.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement