Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Ciąg Fibbonaci'ego w JavaScript
darek29021988
post 25.08.2020, 07:50:05
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 25.08.2020

Ostrzeżenie: (0%)
-----


Utwórz pustą tablicę. Dodaj pierwsze 7 liczb ciągu Fibonacciego za pomocą metod Arrays i wyświetl te liczby jeden po drugim.



Moje rozwiązanie:

let sequFibo = new Array();
modifiedChain = sequFibo.push(1,1,2,3,5,8,13);
let firstElement = console.log(sequFibo[0]);
let secondElement = console.log(sequFibo[1]);
let thirdElement = console.log(sequFibo[2]);
let fourthElement = console.log(sequFibo[3]);
let fifthElement = console.log(sequFibo[4]);
let sixthElement = console.log(sequFibo[5]);
let seventhElement = console.log(sequFibo[6]);

Dlaczego moje rozwiązanie jest nieprawidłowe?
Go to the top of the page
+Quote Post
viking
post 25.08.2020, 07:57:00
Post #2





Grupa: Zarejestrowani
Postów: 6 376
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Bo pewnie chodziło o coś w stylu:

  1. let sequFibo = new Array();
  2. modifiedChain = sequFibo.push(1,1,2,3,5,8,13);
  3. sequFibo.forEach(elem => {
  4. console.log(elem);
  5. });


Chyba że sam ciąg masz też wygenerować.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 7.05.2025 - 07:23