Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Funkcje, return i if / else - zadanie codecademy 8/13
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
andr_w
Jestem w trakcie nauki JS z codecademy.com i mam problem przy zadaniu 8/13

Cytat
1. Define a function called quarter which has a parameter called number.
2. This function returns a value equal to one quarter of the parameter. (i.e. number / 4)
3. Call the function inside the if statement's condition (and put in a parameter value!) such that "The statement is true" is printed to the console.


Napisałem taki kod:

Cytat
var quarter = function(number) {
return number / 4;
};

if (quarter(12) % 4 === 3 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}


Pojawia mi się błąd:

Cytat
TypeError: Property 'quarter' of object [object Object] is not a function


Ma ktoś jakiś pomysł?
kamil4u
Sam kod działa dobrze - ten co podałeś.
Prawdopodobnie resztę kodu masz źle - pytanie, którą część. Napisz więcej informacji.
andr_w
Przed ćwiczeniowym kodem jest jeszcze domyślny kod:
Cytat
1// Define quarter here.
2
3
4
5
6
7 if (quarter() % 3 === 0 ) {
8 console.log("The statement is true");
9 } else {
10 console.log("The statement is false");
11 }


Już wiem po prostu źle umieściłem kod. Ten kod co podałem wcześniej trzeba było wpisać nad tym domyślnym tongue.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.