Challenge 2: Fibonacci Sequence

Learn how to compute the first n numbers of the Fibonacci series in this exercise lesson.

Problem statement

In this exercise, you have to compute the first n numbers of fibonacci sequence of a given $range.

There is a string variable $ans given in which you have to append all the computed Fibonacci numbers one by one.

Here’s a link showing how you can add values to a string.

Input

An integer.

Output

A string.

Sample input

$range = 6

Sample output

Then $ans should have the following stored in it for the sample input given:

Note Just like it is shown in the picture above, the values in the string should have spaces in between them. You can add a space by simply adding quotation marks with space in between them to your string, like this: " ".

Coding challenge

Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.

Good Luck!

#the variable $range contains the number uptil which you need to calculate the fibonacci sequence
# $range is available to you here
$ans = "xyz"; #return the correct string
#write your code for genersting fibonacci sequence here
return $ans;