Advertisement
TZinovieva

Assembly Line JS Advanced

Jun 5th, 2023 (edited)
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createAssemblyLine() {
  2.     return {
  3.         hasClima: function(car) {
  4.             car.temp = 21;
  5.             car.tempSettings = 21;
  6.             car.adjustTemp = function() {
  7.                 if (car.temp < car.tempSettings) {
  8.                     car.temp += 1;
  9.                 } else if (car.temp > car.tempSettings) {
  10.                     car.temp -= 1;
  11.                 }
  12.             };
  13.         },
  14.         hasAudio: function(car) {
  15.             car.currentTrack = {
  16.                 name: null,
  17.                 artist: null,
  18.             };
  19.             car.nowPlaying = function() {
  20.                 if (car.currentTrack !== null) {
  21.                     console.log(`Now playing '${car.currentTrack.name}' by ${car.currentTrack.artist}`);
  22.                 }
  23.             };
  24.         },
  25.         hasParktronic: function(car) {
  26.             car.checkDistance = function(distance) {
  27.                 if (distance < 0.1) {
  28.                     console.log("Beep! Beep! Beep!");
  29.                 } else if (distance >= 0.1 && distance < 0.25) {
  30.                     console.log("Beep! Beep!");
  31.                 } else if (distance >= 0.25 && distance < 0.5) {
  32.                     console.log("Beep!");
  33.                 } else {
  34.                     console.log("");
  35.                 }
  36.             };
  37.         }
  38.     };
  39. }
  40.  
  41. const assemblyLine = createAssemblyLine();
  42. const myCar = { make: 'Toyota',
  43.     model: 'Avensis'
  44. };
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement