* * * * * * * * * * *
b * 2;
alert( a );
* * * * * * * * * * *
a = 21;

b = a * 2;

console.log( b );
* * * * * * * * * * *

alert( b );
* * * * * * * * * * *
age = prompt( "Podaj swj wiek:" );

console.log( age );
* * * * * * * * * * *
a = 2;
b = a + 1;
var a = 20;

a = a + 1;
a = a * 2;
console.log( a );   // 42
* * * * * * * * * * *

"To jest cig tekstowy.";
'To rwnie jest cig tekstowy.';

42;

true;
false;
* * * * * * * * * * *
var a = "42";
var b = Number( a );

console.log( a );   // "42"
console.log( b );   // 42

* * * * * * * * * * *
// To jest komentarz jednowierszowy. 

/* Natomiast to
       jest komentarz
             wielowierszowy.
                      */
var a = 42;     // 42 to sens ycia.
/* Uyta zostaa ponisza warto, poniewa
   zostao dowiedzione, e stanowi odpowied
   na kade pytanie we wszechwiecie. */
var a = 42;
var a = /* Dowolna warto */ 42;

console.log( a );   // 42
* * * * * * * * * * *
var amount = 99.99;

amount = amount * 2;

console.log( amount );      // 199.98

// Konwersja 'amount' na posta cigu tekstowego,
// a nastpnie dodanie "z" na kocu.
amount = String( amount ) + " z";

console.log( amount );      // "199.98 z"
var TAX_RATE = 0.08;    // Stawka podatku: 8%

var amount = 99.99;

amount = amount * 2;

amount = amount + (amount * TAX_RATE);

console.log( amount );              // 215.9784
console.log( amount.toFixed( 2 ) ); // "215.98"

// Poczwszy od wydania ES6:
const TAX_RATE = 0.08;

var amount = 99.99;

// ..

* * * * * * * * * * *
var amount = 99.99;

// Oglny blok kodu
{
    amount = amount * 2;
    console.log( amount );  // 199.98
}
var amount = 99.99;

// Czy warto 'amount' jest wystarczajco dua?
if (amount > 10) {          // <-- Blok doczony do polecenia 'if'
    amount = amount * 2;
    console.log( amount );  // 199.98
}

* * * * * * * * * * *
var bank_balance = 302.13;
var amount = 99.99;

if (amount < bank_balance) {
    console.log( "Chc kupi ten telefon!" );
}
const ACCESSORY_PRICE = 9.99;

var bank_balance = 302.13;
var amount = 99.99;

amount = amount * 2;

// Czy mona sobie pozwoli na dodatkowy zakup?
if ( amount < bank_balance ) {
    console.log( "Wezm jeszcze akcesoria!" );
    amount = amount + ACCESSORY_PRICE;
}
// W przeciwnym razie:
else {
    console.log( "Nie, dzikuj." );
}

* * * * * * * * * * *
while (numOfCustomers > 0) {
    console.log( "Czy mog pomc?" );

    // Pomoc klientowi...

    numOfCustomers = numOfCustomers - 1;
}

// Kontra:

do {
    console.log( "Czy mog pomc?" );

    // Pomoc klientowi...

    numOfCustomers = numOfCustomers - 1;
} while (numOfCustomers > 0);
* * * * * * * * * * *
var i = 0;

// Ptla 'while-true' bdzie dziaaa w nieskoczono, prawda?
while (true) {
    // Czy kontynuowa dziaanie ptli?
    if (i <= 9) {
        console.log( i );
        i = i + 1;
    }
    // Czas zatrzyma ptl!
    else {
        break;
    }
}
// 0 1 2 3 4 5 6 7 8 9

for (var i = 0; i <= 9; i = i + 1) {
    console.log( i );
}
// 0 1 2 3 4 5 6 7 8 9
* * * * * * * * * * *
function printAmount() {
    console.log( amount.toFixed( 2 ) );
}

var amount = 99.99;

printAmount(); // "99.99"

amount = amount * 2;

printAmount(); // "199.98"
function printAmount(amt) {
    console.log( amt.toFixed( 2 ) );
}

function formatAmount() {
    return amount.toFixed( 2 ) + " z";
}

var amount = 99.99;

printAmount( amount * 2 );      // "199.98"

amount = formatAmount();
console.log( amount );    // "99.99 z"
const TAX_RATE = 0.08;

function calculateFinalPurchaseAmount(amt) {
    // Obliczenie nowej wartoci wraz z podatkiem
    amt = amt + (amt * TAX_RATE);

    // Zwrot nowej wartoci
    return amt;
}

var amount = 99.99;

amount = calculateFinalPurchaseAmount( amount );

console.log( amount.toFixed( 2 ) );     // "107.99"
* * * * * * * * * * *
function one() {
    // Ponisza zmienna 'a' istnieje jedynie w funkcji 'one()'.
    var a = 1;
    console.log( a );
}

function two() {
    // Ponisza zmienna 'a' istnieje jedynie w funkcji 'two()'.
    var a = 2;
    console.log( a );
}

one();      // 1
two();      // 2
function outer() {
    var a = 1;

    function inner() {
        var b = 2;

        // W tym miejscu moemy uzyska dostp do 'a' i 'b'.
        console.log( a + b );   // 3
    }

    inner();

    // W tym miejscu moemy uzyska dostp tylko do 'a'.
    console.log( a );           // 1
}

outer();
const TAX_RATE = 0.08;

function calculateFinalPurchaseAmount(amt) {
    // Obliczenie nowej wartoci wraz z podatkiem
    amt = amt + (amt * TAX_RATE);

    // Zwrot nowej wartoci
    return amt;
}
* * * * * * * * * * *
const SPENDING_THRESHOLD = 200;
const TAX_RATE = 0.08;
const PHONE_PRICE = 99.99;
const ACCESSORY_PRICE = 9.99;

var bank_balance = 303.91;
var amount = 0;

function calculateTax(amount) {
    return amount * TAX_RATE;
}

function formatAmount(amount) {
    return amount.toFixed( 2 ) + " z";
}

// Kontynuujemy zakupy telefonw, dopki mamy wystarczajc ilo rodkw na koncie.
while (amount < bank_balance) {
    // Zakup nowego telefonu!
    amount = amount + PHONE_PRICE;

    // Czy mona pozwoli sobie na akcesoria?
    if (amount < SPENDING_THRESHOLD) {
        amount = amount + ACCESSORY_PRICE;
    }
}
// Nie zapomnij odda doli rzdowi.
amount = amount + calculateTax( amount );

console.log(
    "Kwota do zapaty: " + formatAmount( amount )
);
// Kwota do zapaty: 334.76 z

// Czy faktycznie mona pozwoli sobie na ten zakup?
if (amount > bank_balance) {
    console.log(
        "Nie moesz pozwoli sobie na ten zakup. :("
    );
}
// Nie moesz pozwoli sobie na ten zakup. :(