Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------ 17
  2. function triangleOfDolar(number) {
  3.     let printDolar = '';
  4.  
  5.     for (let i = 0; i < number; i++) {
  6.         printDolar += '$';
  7.         console.log(printDolar);
  8.     }
  9. }
  10. ------ 18
  11.  
  12. function checkMovie(arr) {
  13.     let dayInWeek = 0;
  14.     let incomingDay = arr[1].toLowerCase();
  15.     let incomingMovie = arr[0].toLowerCase();
  16.  
  17.     switch (incomingDay) {
  18.         case 'monday':
  19.             dayInWeek = 1;
  20.             break;
  21.         case 'tuesday':
  22.             dayInWeek = 2;
  23.             break;
  24.         case 'wednesday':
  25.             dayInWeek = 3;
  26.             break;
  27.         case 'thursday':
  28.             dayInWeek = 4;
  29.             break;
  30.         case 'friday':
  31.             dayInWeek = 5;
  32.             break;
  33.         case 'saturday':
  34.             dayInWeek = 6;
  35.             break;
  36.         case 'sunday':
  37.             dayInWeek = 7;
  38.             break;
  39.         default:
  40.             console.log('error');
  41.             break;
  42.     }
  43.  
  44.     let cinemaInfo = {};
  45.     cinemaInfo['the godfather'] = [12, 10, 15, 12.50,   15, 25, 30];
  46.     cinemaInfo["schindler's list"] = [8.50, 8.50, 8.50, 8.50, 8.50, 15, 15];
  47.     cinemaInfo['casablanca'] = [8, 8, 8, 8, 8, 10, 10];
  48.     cinemaInfo['the wizard of oz'] = [10, 10, 10, 10, 10, 15, 15];
  49.  
  50.     for(key in cinemaInfo){
  51.         let value = cinemaInfo[key];
  52.         if (key == incomingMovie) {
  53.             console.log(value[dayInWeek -1]);
  54.         } else{
  55.           console.log('error')
  56.         }
  57.     }
  58. }
  59.  
  60. ------ 19
  61. function quadraticEquation(a, b ,c) {
  62.    
  63.  
  64.     let d = Math.pow(b,2) - (4 * a * c);
  65.  
  66.     if (d < 0) {
  67.         console.log('No');
  68.     } else if (d === 0) {
  69.         let x = b * -1 / (2 * a);
  70.         console.log(x);
  71.     } else{
  72.         let x1 = (((b * -1) + (Math.sqrt(d))) / (2 * a));
  73.         let x2 = (((b * -1) - (Math.sqrt(d))) / (2 * a));
  74.  
  75.         console.log(Math.min(x1,x2));
  76.         console.log(Math.max(x1,x2));
  77.     }
  78. }
  79.  
  80. ------ 20
  81.  
  82. function multiplicationTable(tableSize) {
  83.     let openTag = '<tr><th>';
  84.     let middleTag = '</th><th>';
  85.     let closeTag = '</th></tr>';
  86.     let openTableTag = '<table border="1">';
  87.     let closeTableTag = '</table>';
  88.  
  89.     console.log(openTableTag);
  90.     let result = '  ';
  91.     for (let i = 0; i <= tableSize; i++) {
  92.         if (i == 0) {
  93.             result += openTag + 'x';
  94.         }
  95.         else if (i == tableSize) {
  96.             result += middleTag + i + closeTag;
  97.         } else {
  98.             result += middleTag + i;
  99.         }
  100.     }
  101.  
  102.     console.log(result);
  103.     result = '  ';
  104.  
  105.     for (let i = 1; i <= tableSize; i++) {
  106.         result += openTag + i + '</th>';
  107.         for (let j = 1; j <= tableSize; j++) {
  108.             result += '<td>' + `${j * i}` + '</td>';
  109.         }
  110.         result += '</tr>';
  111.  
  112.         console.log(result);
  113.         result = '  ';
  114.        
  115.     }
  116.  
  117.     console.log(closeTableTag);
  118. }
  119.  
  120. ------- 21
  121.  
  122. function printSquare(squareSize) {
  123.     const wall = '-';
  124.     const corner = '+';
  125.     const upperWall = '|';
  126.     const emptySpace = ' ';
  127.     let middleLine = Math.ceil(squareSize / 2);
  128.  
  129.     for (let i = 0; i < (middleLine * 2) - 1 ; i++) {
  130.         if (i === 0 || i === (middleLine * 2) - 2 || i === middleLine - 1) {
  131.             console.log('+' + Array(squareSize - 1).join("-") + '+' + Array(squareSize - 1).join("-") + '+');
  132.         } else {
  133.             console.log('|' + Array(squareSize - 1).join(" ") + '|' + Array(squareSize - 1).join(" ") + '|');
  134.         }
  135.     }
  136. }
  137.  
  138. -------- 22
  139.  
  140. function calendar([day, month, year])
  141. {
  142.     // TODO: return the HTML text holding the calendar table
  143.  
  144.     month--; // months in Date() are [0...11], not [1...12]
  145.     let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  146.     if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
  147.         daysInMonth[1] = 29; // leap year
  148.  
  149.     // Print the calendar table header
  150.     let html = '<table>\n';
  151.     html += '  <tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>\n';
  152.  
  153.     // Print the days of the previous month
  154.     let week = 0;
  155.     let date = new Date(year, month, 1);
  156.     let dayOfWeek = date.getDay();
  157.     let firstDayPrevMonth = daysInMonth[(month-1 + 12) % 12]-dayOfWeek;
  158.     if (dayOfWeek > 0)
  159.         html += '  <tr>';
  160.     for (let i=1; i<=dayOfWeek; i++) {
  161.         html += '<td class="prev-month">' + (firstDayPrevMonth + i) + '</td>';
  162.         week++;
  163.     }
  164.  
  165.     // Print the days of the current month
  166.     let monthDaysCount = daysInMonth[month];
  167.     for (let i=1; i<=monthDaysCount; i++) {
  168.         if (week == 0)
  169.             html += '  <tr>';
  170.         if (day == i)
  171.             html += '<td class="today">' + i + '</td>';
  172.         else
  173.             html += '<td>' + i + '</td>';
  174.         week++;
  175.         if (week == 7) {
  176.             html += '</tr>\n';
  177.             week=0;
  178.         }
  179.     }
  180.  
  181.     // Print the days of the next month
  182.     for (let i=1; week!=0; i++) {
  183.         html += '<td class="next-month">' + i + '</td>';
  184.         week++;
  185.         if (week == 7) {
  186.             html += '</tr>\n';
  187.             week = 0;
  188.         }
  189.     }
  190.  
  191.     html += '</table>';
  192.     return html;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement