4.6 KiB
Arrays and Loops Assignment
Instructions
Complete di following exercises to practice working wit arrays and loops. Each exercise build on concepts from di lesson and encourage you to apply different loop types and array methods.
Exercise 1: Number Pattern Generator
Create one program wey go list every 3rd number between 1-20 and print am to di console.
Requirements:
- Use one
forloop wit custom increment - Display numbers for user-friendly format
- Add descriptive comments wey go explain your logic
Expected Output:
3, 6, 9, 12, 15, 18
Tip: Modify di iteration-expression for your for loop make e skip numbers.
Exercise 2: Array Analysis
Create one array of at least 8 different numbers and write functions to analyze di data.
Requirements:
- Create one array wey dem go call
numberswith at least 8 values - Write one function
findMaximum()wey go return di highest number - Write one function
findMinimum()wey go return di lowest number - Write one function
calculateSum()wey go return di total of all numbers - Test each function and show di results
Bonus Challenge: Create one function wey go find di second highest number inside di array.
Exercise 3: String Array Processing
Create one array of your favorite movies/books/songs and practice different loop types.
Requirements:
- Create one array wit at least 5 string values
- Use traditional
forloop to show items with numbers (1. Item Name) - Use
for...ofloop to show items for uppercase - Use
forEach()method to count and show di total characters
Example Output:
Traditional for loop:
1. The Matrix
2. Inception
3. Interstellar
For...of loop (uppercase):
THE MATRIX
INCEPTION
INTERSTELLAR
Character count:
Total characters across all titles: 42
Exercise 4: Data Filtering (Advanced)
Create one program wey go process array of objects wey represent students.
Requirements:
- Create one array of at least 5 student objects with properties:
name,age,grade - Use loops to find students wey be 18 or older
- Calculate di average grade of all students
- Create new array wey go contain only students wey get grades above 85
Example Structure:
const students = [
{ name: "Alice", age: 17, grade: 92 },
{ name: "Bob", age: 18, grade: 84 },
// Add more pikin dem...
];
Testing Your Code
Test your programs by:
- Running each exercise inside your browser console
- Check outputs make sure dem match di expected results
- Test wit different data sets
- Check say your code fit handle edge cases (empty arrays, single elements)
Submission Guidelines
Include di following inside your submission:
- Well-commented JavaScript code for each exercise
- Screenshots or text output wey show your programs dey run
- Small explanation of which loop type you choose for each task and why
Rubric
| Criteria | Exemplary (3 points) | Adequate (2 points) | Needs Improvement (1 point) |
|---|---|---|---|
| Functionality | All exercises complete correctly wit bonus challenges | All required exercises dey work correctly | Some exercises no complete or get errors |
| Code Quality | Clean, well-organized code wit descriptive variable names | Code dey work but fit be cleaner | Code messy or e hard to understand |
| Comments | Comprehensive comments wey explain logic and decisions | Basic comments dey present | Small or no comments |
| Loop Usage | Shows understanding of different loop types well | Use loops correctly but no variety | Wrong or inefficient loop usage |
| Testing | Proof of thorough testing wit plenty scenarios | Basic testing dey done | No much evidence of testing |
Reflection Questions
After you finish di exercises, think about:
- Which type of loop you enjoy use pass and why?
- Wetin challenge you when you dey work wit arrays?
- How these skills fit help you for real-world web development projects?
- Wetin you for do different if you gots to optimize your code for better performance?
Disclaimer: Dis document don translate wit AI translation service wey dem dey call Co-op Translator. Even though we try make am correct, abeg make you sabi say automated translation fit get some errors or wahala. Di original document wey dem write for im own language na im be correct source. If na important info, better make professional human translation do am. We no go take responsibility if mistake or misunderstanding happen because of dis translation.