-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (63 loc) · 2.26 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const personalMovieDB = {
count: 0,
movies: {},
actors: {},
genres: [],
privat: false,
start: function() {
let numberOfFilms = 0;
do {
numberOfFilms = prompt('How many films have you watched?', '');
} while (numberOfFilms == null || numberOfFilms == '' || isNaN(numberOfFilms));
personalMovieDB.count = numberOfFilms;
},
rememberMyFilms: function() {
for (let i = 0; i < 2; i++) {
let lastFilm = null;
do {
lastFilm = prompt('What was the last movie you watched?', '');
} while(lastFilm == null || lastFilm == '' || lastFilm.length > 50);
let lastFilmRating = null;
do {
lastFilmRating = prompt('How do you rate this?', '');
} while(lastFilmRating == null || lastFilmRating == '' || isNaN(lastFilmRating));
personalMovieDB.movies[lastFilm] = lastFilmRating;
}
},
detectPersonalLevel: function() {
if (personalMovieDB.count > 0 && personalMovieDB.count <= 10) {
alert("You've watched quite a few films!");
} else if (personalMovieDB.count > 10 && personalMovieDB.count <= 30) {
alert('You are a classical spectator!');
} else if (personalMovieDB.count > 30) {
alert('You are a movie fan!');
} else {
alert('Error!');
}
},
writeYourGenres: function() {
for (let i = 0; i < 3; i++) {
let genre = null;
do {
genre = prompt(`What's your favorite genre at number ${i+1}?`, '');
} while (genre == null || genre == '');
personalMovieDB.genres[i] = genre;
}
personalMovieDB.genres.forEach((item, i) => console.log(`Your favorite genre #${i+1} is ${item}`))
},
toggleVisibleMyDB: function() {
personalMovieDB.privat = !personalMovieDB.privat;
},
showMyDB: function() {
if (!personalMovieDB.privat) {
console.log(personalMovieDB);
}
}
}
personalMovieDB.start();
personalMovieDB.rememberMyFilms();
personalMovieDB.detectPersonalLevel();
personalMovieDB.writeYourGenres();
//personalMovieDB.toggleVisibleMyDB();
personalMovieDB.showMyDB();