Skip to content

Commit 5525c9f

Browse files
authored
feat: add faqs section
1 parent 4cb03c7 commit 5525c9f

File tree

1 file changed

+326
-2
lines changed

1 file changed

+326
-2
lines changed

README.md

Lines changed: 326 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Array manipulation is a common task in programming. Whether you are calculating
1313

1414
- Fork this repo
1515
- Clone it to your machine
16-
<br>
16+
<br>
1717

1818

1919
## Submission
@@ -27,7 +27,7 @@ git push origin master
2727
```
2828

2929
- Create a Pull Request so that your TAs can check your work.
30-
<br>
30+
<br>
3131

3232

3333

@@ -214,6 +214,7 @@ const words = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart',
214214
Create function `avg(arr)` that receives any mixed array and calculates average. Consider as mixed array an array filled with numbers and/or strings and/or booleans.
215215

216216
The non-numerical values should be counted as follows:
217+
217218
- Booleans: `true` counts as `1` and `false` counts as `0`.
218219
- Strings: use the string `length` as the numeric value.
219220

@@ -366,3 +367,326 @@ Following the logic you've used in iteration #8.1, declare a function called `gr
366367

367368

368369
**Happy coding!** :heart:
370+
371+
372+
373+
## FAQs
374+
375+
376+
377+
<details>
378+
<summary>I am stuck in the exercise and don't know how to solve the problem or where to start.</summary>
379+
<br>
380+
381+
If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions.
382+
383+
384+
For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources.
385+
386+
387+
Once you have a clear understanding of the problem, you will be able to start working towards the solution.
388+
389+
[Back to top](#faqs)
390+
</details>
391+
392+
393+
394+
<details>
395+
<summary>I am unable to push changes to the repository. What should I do?</summary>
396+
<br>
397+
398+
There are a couple of possible reasons why you may be unable to *push* changes to a Git repository:
399+
400+
1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder:
401+
402+
```bash
403+
git add .
404+
git commit -m "Your commit message"
405+
git push
406+
```
407+
408+
409+
2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository.
410+
To check which remote repository you have cloned, run the following terminal command from the project folder:
411+
412+
```bash
413+
git remote -v
414+
```
415+
416+
If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your Github account first, and then clone your fork to your local machine to be able to push the changes.
417+
418+
Note: You may want to make a copy of the code your have locally, to avoid losing it in the process.
419+
420+
[Back to top](#faqs)
421+
</details>
422+
423+
424+
425+
<details>
426+
<summary>All of the Jasmine tests are failing and in red. Why did this happen?</summary>
427+
<br>
428+
429+
One possible reason why all of the Jasmine tests are failing is that there is a syntax error in the code being tested. If the code contains a syntax error, it will not be loaded properly and none of the tests will be able to run. This will cause all of the tests to fail.
430+
431+
432+
433+
To troubleshoot this issue, you will need to examine the code being tested for syntax errors. Look for missing brackets, semicolons, or other syntax issues that could be causing the problem. If you find a syntax error, correct it and try running the tests again.
434+
435+
436+
437+
438+
Another possibility is that there is an issue with the tests. It is possible that you may have modified the test file and caused an issue. If you have made changes to the test file, try copying and pasting the original test file and running the tests again to see if this resolves the issue.
439+
440+
441+
442+
[Back to top](#faqs)
443+
</details>
444+
445+
446+
447+
<details>
448+
<summary>How do you find a length of a string in JavaScript?</summary>
449+
<br>
450+
451+
To find the length of a string use the `length` property. Here is an example:
452+
453+
```js
454+
const str = "Hello, world!"";
455+
console.log(str.length); // 13
456+
```
457+
458+
The `length` property returns the number of characters in the string, including spaces and special characters.
459+
460+
461+
462+
[Back to top](#faqs)
463+
</details>
464+
465+
466+
467+
<details>
468+
<summary>How do I loop over an array?</summary>
469+
<br>
470+
471+
Loops allow you to repeat a block of code a certain number of times. There are several ways to loop over an array in JavaScript:
472+
473+
474+
475+
<br>
476+
477+
478+
#### For loop
479+
480+
The `for` loop is the most traditional way to loop through an array in JavaScript. It consists of three parts: the *initialization*, the *condition*, and the *increment/decrement*:
481+
482+
```js
483+
const animals = ['cat', 'dog', 'bird'];
484+
485+
// initialize counter variable (let i = 0)
486+
// set condition (i < animals.length)
487+
// increment counter (i++)
488+
for (let i = 0; i < animals.length; i++) {
489+
console.log(animals[i]);
490+
}
491+
```
492+
493+
The initialization is where you declare a counter variable and set its initial value.
494+
495+
The condition is a boolean expression that is evaluated before each iteration of the loop. If the condition is `true`, the loop will continue. Once the condition turns `false`, the loop will terminate.
496+
497+
The increment/decrement is where you update the counter variable and it happens at the end of each iteration.
498+
499+
The block of code inside of the loop is repeatedly during each iteration.
500+
501+
502+
503+
<br>
504+
505+
#### While loop
506+
507+
The `while` loop is another way to loop through an array in JavaScript. It consists of a condition and a block of code that is executed as long as the condition is `true`.
508+
509+
510+
511+
Like the `for` loop, the `while` loop requires a counter variable to keep track of the current position in the array. The counter variable must be initialized before the loop, and incremented or decremented at the end of each iteration.
512+
513+
```js
514+
const animals = ['cat', 'dog', 'bird'];
515+
516+
// initialize counter variable (i)
517+
let i = 0;
518+
519+
// set condition (i < animals.length)
520+
while (i < animals.length) {
521+
console.log(animals[i]);
522+
523+
// increment counter (i++)
524+
i++;
525+
}
526+
```
527+
528+
529+
530+
[Back to top](#faqs)
531+
</details>
532+
533+
534+
535+
536+
537+
<details>
538+
<summary>How do I loop over an array using the <code>forEach()</code> method?</summary>
539+
<br>
540+
541+
The `forEach()` method executes a provided function once for each array element. It does not return a new array, but rather executes the function on each element in the array.
542+
543+
544+
545+
The syntax of the `forEach()` method is as follows:
546+
547+
```js
548+
array.forEach( function(element) {
549+
// code to be executed for each element
550+
});
551+
```
552+
553+
<br>
554+
555+
Here is an example that uses the `forEach()` method to log each element and its index in an array to the console:
556+
557+
```js
558+
const fruits = ['apple', 'banana', 'cherry'];
559+
560+
fruits.forEach( function(element, index) {
561+
console.log(`${index}: ${element}`);
562+
});
563+
```
564+
565+
<br>
566+
567+
You can also use an arrow function as the callback function for `forEach()`:
568+
569+
```js
570+
fruits.forEach((element, index) => {
571+
console.log(`${index}: ${element}`);
572+
});
573+
```
574+
575+
576+
577+
[Back to top](#faqs)
578+
</details>
579+
580+
581+
582+
<details>
583+
<summary>What could cause <code>array.length</code> to return <code>undefined</code>?</summary>
584+
<br>
585+
586+
If you try to access the `.length` property on an array (e.g., `array.length`) but you are getting `undefined` it means that the variable you are accessing is not actually an array.
587+
<br>
588+
589+
590+
**How do I fix this?**
591+
592+
Check that the variable you are trying to access is actually an array.
593+
594+
595+
596+
[Back to top](#faqs)
597+
</details>
598+
599+
600+
601+
602+
603+
<details>
604+
<summary>Why is my function returning the last element of the array instead of the longest one?</summary>
605+
<br>
606+
607+
Your function might not be correctly checking for the longest element in the array. In other words, there may be an issue with the logic of the conditional statements in the function, or with the comparison being used in the conditionals.
608+
609+
610+
611+
To fix this issue, you should check the logic of the conditional statements in the function.
612+
613+
614+
615+
[Back to top](#faqs)
616+
</details>
617+
618+
619+
620+
<details>
621+
<summary>How can I compare the length of each word in an array in JavaScript?</summary>
622+
<br>
623+
624+
To compare the length of each word in an array in JavaScript, you can use a loop to iterate through the array and compare the length of each element using the `.length` property.
625+
626+
627+
628+
629+
Here is an example of how you loop over an array:
630+
631+
```js
632+
function findLongestWord(words) {
633+
for (let i = 0; i < words.length; i++) {
634+
console.log(words[i]);
635+
}
636+
}
637+
```
638+
639+
<br>
640+
641+
To compare the length of each element you should use a conditional statement in the following way:
642+
643+
```js
644+
if ( words[i].length > longestWord.length) {
645+
console.log(`${words[i].length} is longer than ${longestWord.length}`);
646+
}
647+
```
648+
649+
650+
651+
[Back to top](#faqs)
652+
</details>
653+
654+
655+
656+
657+
658+
<details>
659+
<summary>I am unable to push changes to the repository. What should I do?</summary>
660+
<br>
661+
662+
There are a couple of possible reasons why you may be unable to *push* changes to a Git repository:
663+
664+
1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder:
665+
666+
```bash
667+
git add .
668+
git commit -m "Your commit message"
669+
git push
670+
```
671+
672+
673+
674+
675+
676+
677+
2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository.
678+
To check which remote repository you have cloned, run the following terminal command from the project folder:
679+
680+
```bash
681+
git remote -v
682+
```
683+
684+
If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your Github account first, and then clone your fork to your local machine to be able to push the changes.
685+
686+
Note: You may want to make a copy of the code your have locally, to avoid losing it in the process.
687+
688+
689+
690+
[Back to top](#faqs)
691+
</details>
692+

0 commit comments

Comments
 (0)