parent
5bac96af11
commit
62a6a5377e
@ -1,11 +1,87 @@
|
||||
# Data Types Practice
|
||||
# Data Types Practice: E-commerce Shopping Cart
|
||||
|
||||
## Instructions
|
||||
|
||||
Imagine you are building a shopping cart. Write documentation on the data types you would need to complete your shopping experience. For each data type, explain how and why you would use it, and provide an example. The six JavaScript data types are: String, Number, Boolean, Null, Undefined, and Object.
|
||||
Imagine you are building a modern e-commerce shopping cart system. This assignment will help you understand how different JavaScript data types work together to create real-world applications.
|
||||
|
||||
### Your Task
|
||||
|
||||
Create a comprehensive analysis of how you would use JavaScript data types in a shopping cart application. For each of the seven primitive data types and objects, you need to:
|
||||
|
||||
1. **Identify** the data type and its purpose
|
||||
2. **Explain** why this data type is the best choice for specific shopping cart features
|
||||
3. **Provide** realistic code examples showing the data type in action
|
||||
4. **Describe** how this data type interacts with other parts of the shopping cart
|
||||
|
||||
### Required Data Types to Cover
|
||||
|
||||
**Primitive Data Types:**
|
||||
- **String**: Product names, descriptions, user information
|
||||
- **Number**: Prices, quantities, tax calculations
|
||||
- **Boolean**: Item availability, user preferences, cart status
|
||||
- **Null**: Intentionally empty values (like missing discount codes)
|
||||
- **Undefined**: Uninitialized values or missing data
|
||||
- **Symbol**: Unique identifiers (advanced use)
|
||||
- **BigInt**: Large financial calculations (advanced use)
|
||||
|
||||
**Reference Types:**
|
||||
- **Object**: Product details, user profiles, cart contents
|
||||
- **Array**: List of products, order history, categories
|
||||
|
||||
### Example Format for Each Data Type
|
||||
|
||||
For each data type, structure your response like this:
|
||||
|
||||
```markdown
|
||||
## [Data Type Name]
|
||||
|
||||
**Purpose in Shopping Cart:** [Explain what this data type does]
|
||||
|
||||
**Why This Type:** [Explain why this is the best choice]
|
||||
|
||||
**Code Example:**
|
||||
```javascript
|
||||
// Your realistic code example here
|
||||
```
|
||||
|
||||
**Real-world Usage:** [Describe how this would work in practice]
|
||||
|
||||
**Interactions:** [Explain how this data type works with others]
|
||||
```
|
||||
|
||||
### Bonus Challenges
|
||||
|
||||
1. **Type Coercion**: Show an example where JavaScript automatically converts between data types in your shopping cart (e.g., string "5" + number 10)
|
||||
|
||||
2. **Data Validation**: Demonstrate how you would check if user input is the correct data type before processing
|
||||
|
||||
3. **Performance Considerations**: Explain when you might choose one data type over another for performance reasons
|
||||
|
||||
### Submission Guidelines
|
||||
|
||||
- Create a markdown document with clear headings for each data type
|
||||
- Include working JavaScript code examples
|
||||
- Use realistic e-commerce scenarios in your examples
|
||||
- Explain your reasoning clearly for beginners to understand
|
||||
- Test your code examples to ensure they work correctly
|
||||
|
||||
## Rubric
|
||||
|
||||
Criteria | Exemplary | Adequate | Needs Improvement
|
||||
--- | --- | --- | -- |
|
||||
Data Types | All six data types are listed, explored in detail, and documented with examples | Four data types are explored with some explanation | Two data types are explored with minimal explanation |
|
||||
| Criteria | Exemplary (90-100%) | Proficient (80-89%) | Developing (70-79%) | Needs Improvement (Below 70%) |
|
||||
|----------|---------------------|---------------------|---------------------|------------------------------|
|
||||
| **Data Type Coverage** | All 7 primitive types and objects/arrays covered with detailed explanations | 6-7 data types covered with good explanations | 4-5 data types covered with basic explanations | Fewer than 4 data types or minimal explanations |
|
||||
| **Code Examples** | All examples are realistic, working, and well-commented | Most examples work and are relevant to e-commerce | Some examples work but may be generic | Code examples are incomplete or non-functional |
|
||||
| **Real-world Application** | Clearly connects each data type to practical shopping cart features | Good connection to e-commerce scenarios | Some connection to shopping cart context | Limited real-world application demonstrated |
|
||||
| **Technical Accuracy** | All technical information is correct and demonstrates deep understanding | Most technical information is accurate | Generally accurate with minor errors | Contains significant technical errors |
|
||||
| **Communication** | Explanations are clear, beginner-friendly, and well-organized | Good explanations that are mostly clear | Explanations are understandable but may lack clarity | Explanations are unclear or poorly organized |
|
||||
| **Bonus Elements** | Includes multiple bonus challenges with excellent execution | Includes one or more bonus challenges well done | Attempts bonus challenges with mixed success | No bonus challenges attempted |
|
||||
|
||||
### Learning Objectives
|
||||
|
||||
By completing this assignment, you will:
|
||||
- ✅ **Understand** the seven JavaScript primitive data types and their uses
|
||||
- ✅ **Apply** data types to real-world programming scenarios
|
||||
- ✅ **Analyze** when to choose specific data types for different purposes
|
||||
- ✅ **Create** working code examples that demonstrate data type usage
|
||||
- ✅ **Explain** technical concepts in beginner-friendly language
|
||||
- ✅ **Connect** fundamental programming concepts to practical applications
|
||||
@ -1,40 +1,104 @@
|
||||
# Operators
|
||||
# Making Decisions: Student Grade Processor
|
||||
|
||||
## Instructions
|
||||
## Learning Objectives
|
||||
|
||||
Play around with operators. Here's a suggestion for a program you can implement:
|
||||
In this assignment, you'll practice the decision-making concepts from this lesson by building a program that processes student grades from different grading systems. You'll use `if...else` statements, comparison operators, and logical operators to determine which students pass their courses.
|
||||
|
||||
You have a set of students from two different grading systems.
|
||||
## The Challenge
|
||||
|
||||
### First grading system
|
||||
You work for a school that recently merged with another institution. Now you need to process student grades from two completely different grading systems and determine which students are passing. This is a perfect opportunity to practice conditional logic!
|
||||
|
||||
One grading system is defined as grades being from 1-5 where 3 and above means you pass the course.
|
||||
### Understanding the Grading Systems
|
||||
|
||||
### Second grading system
|
||||
#### First Grading System (Numeric)
|
||||
- Grades are given as numbers from 1-5
|
||||
- **Passing grade**: 3 and above (3, 4, or 5)
|
||||
- **Failing grade**: Below 3 (1 or 2)
|
||||
|
||||
The other grade system has the following grades `A, A-, B, B-, C, C-` where `A` is the top grade and `C` is the lowest passing grade.
|
||||
#### Second Grading System (Letter Grades)
|
||||
- Grades use letters: `A`, `A-`, `B`, `B-`, `C`, `C-`
|
||||
- **Passing grades**: `A`, `A-`, `B`, `B-`, `C`, `C-` (all listed grades are passing)
|
||||
- **Note**: This system doesn't include failing grades like `D` or `F`
|
||||
|
||||
### The task
|
||||
### Your Task
|
||||
|
||||
Given the following array `allStudents` representing all students and their grades, construct a new array `studentsWhoPass` containing all students who pass.
|
||||
|
||||
> TIP, use a for-loop and if...else and comparison operators:
|
||||
Given the following array `allStudents` representing all students and their grades, construct a new array `studentsWhoPass` containing all students who pass according to their respective grading systems.
|
||||
|
||||
```javascript
|
||||
let allStudents = [
|
||||
'A',
|
||||
'B-',
|
||||
1,
|
||||
4,
|
||||
5,
|
||||
2
|
||||
]
|
||||
'A', // Letter grade - passing
|
||||
'B-', // Letter grade - passing
|
||||
1, // Numeric grade - failing
|
||||
4, // Numeric grade - passing
|
||||
5, // Numeric grade - passing
|
||||
2 // Numeric grade - failing
|
||||
];
|
||||
|
||||
let studentsWhoPass = [];
|
||||
```
|
||||
|
||||
### Step-by-Step Approach
|
||||
|
||||
1. **Set up a loop** to go through each grade in the `allStudents` array
|
||||
2. **Check the grade type** (is it a number or a string?)
|
||||
3. **Apply the appropriate grading system rules**:
|
||||
- For numbers: check if grade >= 3
|
||||
- For strings: check if it's one of the valid passing letter grades
|
||||
4. **Add passing grades** to the `studentsWhoPass` array
|
||||
|
||||
### Helpful Code Techniques
|
||||
|
||||
Use these JavaScript concepts from the lesson:
|
||||
|
||||
- **typeof operator**: `typeof grade === 'number'` to check if it's a numeric grade
|
||||
- **Comparison operators**: `>=` to compare numeric grades
|
||||
- **Logical operators**: `||` to check multiple letter grade conditions
|
||||
- **if...else statements**: to handle different grading systems
|
||||
- **Array methods**: `.push()` to add passing grades to your new array
|
||||
|
||||
### Expected Output
|
||||
|
||||
When you run your program, `studentsWhoPass` should contain: `['A', 'B-', 4, 5]`
|
||||
|
||||
**Why these grades pass:**
|
||||
- `'A'` and `'B-'` are valid letter grades (all letter grades in this system are passing)
|
||||
- `4` and `5` are numeric grades >= 3
|
||||
- `1` and `2` fail because they're numeric grades < 3
|
||||
|
||||
## Testing Your Solution
|
||||
|
||||
Test your code with different scenarios:
|
||||
|
||||
```javascript
|
||||
// Test with different grade combinations
|
||||
let testGrades1 = ['A-', 3, 'C', 1, 'B'];
|
||||
let testGrades2 = [5, 'A', 2, 'C-', 4];
|
||||
|
||||
// Your solution should work with any combination of valid grades
|
||||
```
|
||||
|
||||
## Bonus Challenges
|
||||
|
||||
Once you complete the basic assignment, try these extensions:
|
||||
|
||||
1. **Add validation**: Check for invalid grades (like negative numbers or invalid letters)
|
||||
2. **Count statistics**: Calculate how many students pass vs. fail
|
||||
3. **Grade conversion**: Convert all grades to a single numeric system (A=5, B=4, C=3, etc.)
|
||||
|
||||
## Rubric
|
||||
|
||||
| Criteria | Exemplary | Adequate | Needs Improvement |
|
||||
| -------- | ------------------------------ | ----------------------------- | ------------------------------- |
|
||||
| | Complete solution is presented | Partial solution is presented | Solution with bugs is presented |
|
||||
| Criteria | Exemplary (4) | Proficient (3) | Developing (2) | Beginning (1) |
|
||||
|----------|---------------|----------------|----------------|---------------|
|
||||
| **Functionality** | Program correctly identifies all passing grades from both systems | Program works with minor issues or edge cases | Program partially works but has logical errors | Program has significant errors or doesn't run |
|
||||
| **Code Structure** | Clean, well-organized code with proper if...else logic | Good structure with appropriate conditional statements | Acceptable structure with some organizational issues | Poor structure, difficult to follow logic |
|
||||
| **Use of Concepts** | Effectively uses comparison operators, logical operators, and conditional statements | Good use of lesson concepts with minor gaps | Some use of lesson concepts but missing key elements | Limited use of lesson concepts |
|
||||
| **Problem Solving** | Shows clear understanding of the problem and elegant solution approach | Good problem-solving approach with solid logic | Adequate problem-solving with some confusion | Unclear approach, doesn't demonstrate understanding |
|
||||
|
||||
## Submission Guidelines
|
||||
|
||||
1. **Test your code** thoroughly with the provided examples
|
||||
2. **Add comments** explaining your logic, especially for the conditional statements
|
||||
3. **Verify output** matches expected results: `['A', 'B-', 4, 5]`
|
||||
4. **Consider edge cases** like empty arrays or unexpected data types
|
||||
|
||||
> 💡 **Pro Tip**: Start simple! Get the basic functionality working first, then add more sophisticated features. Remember, the goal is to practice decision-making logic with the tools you learned in this lesson.
|
||||
|
||||
@ -1,13 +1,108 @@
|
||||
# Loop an Array
|
||||
# Arrays and Loops Assignment
|
||||
|
||||
## Instructions
|
||||
|
||||
Complete the following exercises to practice working with arrays and loops. Each exercise builds on concepts from the lesson and encourages you to apply different loop types and array methods.
|
||||
|
||||
### Exercise 1: Number Pattern Generator
|
||||
Create a program that lists every 3rd number between 1-20 and prints it to the console.
|
||||
|
||||
> TIP: use a for-loop and modify the iteration-expression
|
||||
**Requirements:**
|
||||
- Use a `for` loop with a custom increment
|
||||
- Display numbers in a user-friendly format
|
||||
- Add descriptive comments explaining your logic
|
||||
|
||||
**Expected Output:**
|
||||
```
|
||||
3, 6, 9, 12, 15, 18
|
||||
```
|
||||
|
||||
> **Tip:** Modify the iteration-expression in your for loop to skip numbers.
|
||||
|
||||
### Exercise 2: Array Analysis
|
||||
Create an array of at least 8 different numbers and write functions to analyze the data.
|
||||
|
||||
**Requirements:**
|
||||
- Create an array called `numbers` with at least 8 values
|
||||
- Write a function `findMaximum()` that returns the highest number
|
||||
- Write a function `findMinimum()` that returns the lowest number
|
||||
- Write a function `calculateSum()` that returns the total of all numbers
|
||||
- Test each function and display the results
|
||||
|
||||
**Bonus Challenge:** Create a function that finds the second highest number in the array.
|
||||
|
||||
### Exercise 3: String Array Processing
|
||||
Create an array of your favorite movies/books/songs and practice different loop types.
|
||||
|
||||
**Requirements:**
|
||||
- Create an array with at least 5 string values
|
||||
- Use a traditional `for` loop to display items with numbers (1. Item Name)
|
||||
- Use a `for...of` loop to display items in uppercase
|
||||
- Use `forEach()` method to count and display the 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 a program that processes an array of objects representing students.
|
||||
|
||||
**Requirements:**
|
||||
- Create an array of at least 5 student objects with properties: `name`, `age`, `grade`
|
||||
- Use loops to find students who are 18 or older
|
||||
- Calculate the average grade of all students
|
||||
- Create a new array containing only students with grades above 85
|
||||
|
||||
**Example Structure:**
|
||||
```javascript
|
||||
const students = [
|
||||
{ name: "Alice", age: 17, grade: 92 },
|
||||
{ name: "Bob", age: 18, grade: 84 },
|
||||
// Add more students...
|
||||
];
|
||||
```
|
||||
|
||||
## Testing Your Code
|
||||
|
||||
Test your programs by:
|
||||
1. Running each exercise in your browser's console
|
||||
2. Verifying outputs match expected results
|
||||
3. Testing with different data sets
|
||||
4. Checking that your code handles edge cases (empty arrays, single elements)
|
||||
|
||||
## Submission Guidelines
|
||||
|
||||
Include the following in your submission:
|
||||
- Well-commented JavaScript code for each exercise
|
||||
- Screenshots or text output showing your programs running
|
||||
- Brief explanation of which loop type you chose for each task and why
|
||||
|
||||
## Rubric
|
||||
|
||||
| Criteria | Exemplary | Adequate | Needs Improvement |
|
||||
| -------- | --------------------------------------- | ------------------------ | ------------------------------ |
|
||||
| | Program runs correctly and is commented | Program is not commented | Program is incomplete or buggy |
|
||||
| Criteria | Exemplary (3 points) | Adequate (2 points) | Needs Improvement (1 point) |
|
||||
| -------- | -------------------- | ------------------- | --------------------------- |
|
||||
| **Functionality** | All exercises completed correctly with bonus challenges | All required exercises work correctly | Some exercises incomplete or contain errors |
|
||||
| **Code Quality** | Clean, well-organized code with descriptive variable names | Code works but could be cleaner | Code is messy or hard to understand |
|
||||
| **Comments** | Comprehensive comments explaining logic and decisions | Basic comments present | Minimal or no comments |
|
||||
| **Loop Usage** | Demonstrates understanding of different loop types appropriately | Uses loops correctly but limited variety | Incorrect or inefficient loop usage |
|
||||
| **Testing** | Evidence of thorough testing with multiple scenarios | Basic testing demonstrated | Little evidence of testing |
|
||||
|
||||
## Reflection Questions
|
||||
|
||||
After completing the exercises, consider:
|
||||
1. Which type of loop felt most natural to use and why?
|
||||
2. What challenges did you encounter when working with arrays?
|
||||
3. How could these skills apply to real-world web development projects?
|
||||
4. What would you do differently if you had to optimize your code for performance?
|
||||
Loading…
Reference in new issue