<repo_name>DimaSanKiev/JavaScriptBasics<file_sep>/5-functions/5-1_return/random.js
function getRandomNumber(upper) {
    return Math.floor(Math.random() * upper) + 1;
}

console.log(getRandomNumber());
console.log(getRandomNumber(6));
console.log(getRandomNumber(100));
console.log(getRandomNumber(10000));
console.log(getRandomNumber(2));
<file_sep>/7-arrays/7-6_two_dimensional_arrays/playlist.js
var playList = [
    ['Time Is The Healer (Monada Bootleg Dub)', 'Riva'],
    ['<NAME>oods & W&W', 'Trigger'],
    ['Filmic (Ruben de Ronde Remix)', 'Above & Beyond'],
    ['200 (FSOE 200 Anthem)', 'Aly & Fila'],
    ['An Angel\'s Love (Vocal Mix)', '<NAME>. feat. <NAME>'],
    ['Black Is The Color (<NAME> Vs. 2 Devine rmx)', 'DJ vEQ']
];

function print(message) {
    document.write(message);
}

function printSongs(songs) {
    var listHTML = '<ol>';
    for (var i = 0; i < songs.length; i += 1) {
        listHTML += '<li><b>' + songs[i][0] + '</b> by <b>' + songs[i][1] + '</b></li>';
    }
    listHTML += '</ol>';
    print(listHTML);
}

printSongs(playList);





















<file_sep>/7-arrays/7-2_adding_data/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Musical Playlist</title>
    <link rel="stylesheet" href="../../css/styles.css">
</head>
<body>
<h1>My Music Playlist</h1>
<p>The <b>push()</b> method adds one or more elements to the end of an array and returns the new
    length of the array.</p>
<p>The <b>unshift()</b> method adds one or more elements to the beginning of an array and returns the new
    length of the array.</p>
<div id="listDiv">

</div>
<script src="helpers.js"></script>
<script src="playlist.js"></script>
</body>
</html><file_sep>/7-arrays/7-7_quiz_challenge/quiz.js
var questions = [
    ['What is the name of a markup language for describing web documents (web pages)?', 'HTML'],
    ['What language describes how HTML elements are to be displayed on screen, paper, or in other media?', 'CSS'],
    ['What is the name of a powerful and popular language for programming on the web?', 'JavaScript'],
    ['What is a name of standard language for accessing databases?', 'SQL'],
    ['What is the most popular programming language?', 'Java']
];
var rightAnswers = 0;
var question;
var answer;
var input;
var correctAnswers = [];
var wrongAnswers = [];

function print(message) {
    var outputDiv = document.getElementById('output');
    outputDiv.innerHTML = message;
}

function buildList(list) {
    var listHTML = '<ol>';
    for (var i = 0; i < list.length; i += 1) {
        listHTML += '<li>' + list[i][0] + ' -' + list[i][1] + '</li>';
    }
    listHTML += '</ol>';
    return listHTML;
}

for (var i = 0; i < questions.length; i++) {
    question = questions[i][0];
    answer = questions[i][1].toUpperCase();
    input = prompt(question).toUpperCase();
    if (input === answer) {
        rightAnswers++;
        correctAnswers.push([question, input]);
    } else {
        wrongAnswers.push([question, input]);
    }
}

report = '<br/><h2>You got <b>' + rightAnswers + '</b> right answer(s).</h2>';

if (correctAnswers.length > 0) {
    html += '<p style="color: green">You got these question(s) correct:</p>';
    html += buildList(correctAnswers);
    if (wrongAnswers.length === 0) {
        html += '<p>You haven\'t any incorrect answers, congratulations!</p>';
    }
}

if (wrongAnswers.length > 0) {
    html += '<p style="color: darkred">You got these question(s) wrong:</p>';
    html += buildList(wrongAnswers);
    if (correctAnswers.length === 0) {
        html += '<p>Sorry, all your answers are wrong... Study more and try again.</p>';
    }
}

print(html);<file_sep>/7-arrays/7-2_adding_data/playlist.js
var playlist = [];

// The push() method adds one or more elements to the end of an array and returns the new length of the array.
playlist.push('Anthem');
playlist.push('Angel\'s Love', 'Black Is The Color');

// The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
playlist.unshift('Filmic');
playlist.unshift('Time Is The Healer', 'Trigger');

buildList(playlist);<file_sep>/4-decisions/4-3_quiz_game/quiz.js
// quiz begins, no answers correct
var correctAnswers = 0;
alert('Please answer the 5 following questions.');

// ask questions
var answer1 = prompt('How much seconds does it take for light to reach the Moon from the Earth?');
if (parseInt(answer1) === 1) {
    correctAnswers += 1;
}
var answer2 = prompt('What is the capital of Australia?');
if (answer2.toUpperCase() === 'CANBERRA') {
    correctAnswers += 1;
}
var answer3 = prompt('A brick weighs 1kg plus a half of a brick. How much kilograms does a brick weigh?');
if (parseInt(answer3) === 2) {
    correctAnswers += 1;
}
var answer4 = prompt('What is the most popular programming language in 2016?');
if (answer4.toUpperCase() === 'JAVA') {
    correctAnswers += 1;
}
var answer5 = prompt('What is the major chemical element human body consists of?');
if (answer5.toUpperCase() === 'OXYGEN' || answer5.toUpperCase() === 'O2' || answer5.toUpperCase() === 'O') {
    correctAnswers += 1;
}

// output results
document.write('<p>You got ' + correctAnswers + ' out of 5 questions correct</p>');

// output rank
if (correctAnswers === 5) {
    document.write('<p><strong>You won a GOLD medal!</strong></p>');
} else if (correctAnswers >= 3) {
    document.write('<p><strong>You won a SILVER medal!</strong></p>');
} else if (correctAnswers >= 1) {
    document.write('<p><strong>You won a BRONZE medal!</strong></p>');
} else {
    document.write('<p><strong>Sorry, you need to study more, try again later.</strong></p>')
}
<file_sep>/3-numbers/3-3_random_number/app.js
var dieRolll = Math.floor(Math.random() * 6 + 1);
alert('You rolled a ' + dieRolll);<file_sep>/7-arrays/7-5_array_methods/search.js
/*
 The join() method takes an array and returns a string with all the items in the array
 separated by a supplied character, such as comma or a colon.
 This is a great way to display all the items in an array in a single line.
 */

/*
 Another useful method is concat(). It can be used to add one list to another.
 */

/*
 The indexOf() method lets to search an array for a particular value. If the value is in
 the list, than that element's position is returned. However, if the item is not in the list,
 then the indexOf() method returns the value -1.
 */

var inStock = ['apples', 'eggs', 'milk', 'cookies', 'cheese', 'bread', 'lettuce', 'carrot',
    'broccoli', 'pizza', 'potato', 'crackers', 'onion', 'tofu', 'frozen dinner', 'cucumber'];
var search;

function print(message) {
    document.write('<p>' + message + '</p>');
}

while (true) {
    search = prompt('Search for a product in our store. Type \'list\' to show all of the' +
        ' produce and \'quit\' to exit');
    search = search.toLowerCase();
    if (search === 'quit') {
        break;
    } else if (search === 'list') {
        print(inStock.join(', '));
    } else {
        if (inStock.indexOf(search) > -1) {
            print('Yes, we have ' + search + ' in the store.');
        } else {
            print('– ' + search + ' is not in stock.');
        }
    }
}<file_sep>/5-functions/5-3_random_number_challenge/random.js
function generateRandomNumber(lower, upper) {
    return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}

var min = parseInt(prompt('Insert the lower number:'));
var max = parseInt(prompt('Insert the upper number:'));

if (isNaN(max) || isNaN(max)) {
    document.write('<p>Please enter the numbers.</p>');
    throw new Error('Please enter the numbers.');
} else {
    var random = generateRandomNumber(min, max);
    document.write('<p>The random number between ' + min + ' and ' + max + ' is ' + random + '.</p>');
}<file_sep>/8-objects/8-4_students_challenge/student_report.js
var message;
var student;
var search;

function print(message) {
    var outputDiv = document.getElementById('output');
    outputDiv.innerHTML = message;
}

function getStudentReport(results) {
    var report = '';
    for (var i = 0; i < results.length; i++) {
        report += '<h2>Student: ' + results[i].name + '</h2>';
        report += '<p>Track: ' + results[i].track + '</p>';
        report += '<p>Achievements: ' + results[i].achievements + '</p>';
        report += '<p>Points: ' + results[i].points + '</p>';
    }
    return report;
}

while (true) {
    var results = [];
    message = '';
    search = prompt('Please input student\'s name [John] (or type \'quit\' to exit):');
    if (search === null || search.toLowerCase() === 'quit') {
        break;
    } else {
        for (var i = 0; i < students.length; i++) {
            student = students[i];
            if (student.name === search) {
                results.push(student);
            }
            message = getStudentReport(results);
            print(message);
        }
        results.length = 0;
        if (message === '') {
            message = '<h2>There is no such student with name ' + search + '.</h2>';
            print(message);
        }
    }
}<file_sep>/1-intro/1-1/scripts.js
alert("Hello user");
document.write("<h1>Welcome to JavaScript Basics</h1>");
alert("Thanks for visiting");<file_sep>/3-numbers/3-4_random_challenge/random.js
var min = parseInt(prompt('Please input minimum number:'));
var max = parseInt(prompt('Please input maximum number:'));

var random = Math.floor(Math.random() * (max - min + 1)) + min;
var message = 'The random number from ' + min + ' and ' + max + ' is ' + random;

document.write(message);<file_sep>/5-functions/5-2_parameters/area.js
function getArea(width, length, unit) {
    var area = width * length;
    return area + " " + unit;
}

console.log(getArea(10, 20, 'sq m'));