Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function favoriteMovie(input) {
- let index = 0;
- let name = input[index];
- index++;
- let favouriteName = "";
- let bestPoints = 0;
- let counter = 0;
- while (name !== "STOP") {
- counter++;
- let points = 0;
- let movieValue = 0;
- for (let i = 0; i < name.length; i++) {
- points = name.charCodeAt(i);
- if (points >= 97 && points <= 122) {
- points -= name.length * 2;
- } else if (points >= 65 && points <= 90) {
- points -= name.length;
- }
- movieValue += points;
- }
- if (movieValue >= bestPoints) {
- bestPoints = movieValue;
- favouriteName = name;
- }
- name = input[index];
- index++;
- if (counter === 7) {
- break;
- }
- }
- if (counter >= 7) {
- console.log(`The limit is reached.`);
- console.log(`The best movie for you is ${favouriteName} with ${bestPoints} ASCII sum.`);
- } else {
- console.log(`The best movie for you is ${favouriteName} with ${bestPoints} ASCII sum.`)
- }
- }
Advertisement
Comments
-
- The JavaScript string charCodeAt() method is used to find out the Unicode value of a character at the specific index in a string.
Add Comment
Please, Sign In to add comment