Extenza-Academy / WebDev-100_2021-Q1

24 Lessons, 12 Weeks, Get Started as a Web Developer
2 stars 0 forks source link

2.3.6. Assignment #54

Closed mserykh closed 3 years ago

mserykh commented 3 years ago

Assignment

Operators

Instructions

Play around with operators. Here's a suggestion for a program you can implement:

You have a set of students from two different grading systems.

First grading system

One grading system is defined as grades being from 1-5 where 3 and above means you pass the course.

Second grading system

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.

The 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:

let allStudents = [
  'A',
  'B-'
  1,
  4
  5,
  2
]

let studentsWhoPass = [];

Rubric

Criteria Exemplary Adequate Needs Improvement
Complete solution is presented Partial solution is presented Solution with bugs is presented
mserykh commented 3 years ago
let allStudents = [
    'A',
    'B-',
    1,
    4,
    5,
    2
  ]

  let studentsWhoPass = [];

  for (let i = 0; i < allStudents.length; i++) {
    if (allStudents[i] >= 3 || allStudents[i] === 'A' || allStudents[i] === 'A-' || allStudents[i] === 'B' || allStudents[i] === 'B-') {
        studentsWhoPass.push(allStudents[i]);
    }
  }

  console.log(studentsWhoPass);
mserykh commented 3 years ago

@dev-experience please note that initial array has missing ,:

let allStudents = [
  'A',
  'B-'
  1,
  4
  5,
  2
]
dev-experience commented 3 years ago

@dev-experience please note that initial array has missing ,:

let allStudents = [
  'A',
  'B-'
  1,
  4
  5,
  2
]

@mserykh could you please fix it via a pull request?

dev-experience commented 3 years ago

@mserykh please check my comments in the code.

// What is the reason for `let`?
let allStudents = [
    'A',
    'B-',
    1,
    4,
    5,
    2
  ] // No semicolon

// What happened with the indentation?
  let studentsWhoPass = [];

// Is there reason for `let`?
  for (let i = 0; i < allStudents.length; i++) {
    // Please be aware that `>=` doesn't check data types
    // Do you mind extracting the check to a function for cleaner code?
    if (allStudents[i] >= 3 || allStudents[i] === 'A' || allStudents[i] === 'A-' || allStudents[i] === 'B' || allStudents[i] === 'B-') {
        // Conceptual question: how the result of `[A, B-, 1, 4, 5]` tells you which particular student pass which don't?
        studentsWhoPass.push(allStudents[i]);
    }
  }

  console.log(studentsWhoPass);
mserykh commented 3 years ago

@dev-experience please note that initial array has missing ,:

let allStudents = [
  'A',
  'B-'
  1,
  4
  5,
  2
]

@mserykh could you please fix it via a pull request? @dev-experience please see a PR

mserykh commented 3 years ago
const allStudents = ["A", "B-", 1, 4, 5, 2];

const isPass = mark => mark >= 3 || mark === "A" || mark === "A-" || mark === "B" || mark === "B-";

const findStudentsWhoPass = marks => {
    const result = [];

    for (let i = 0; i < marks.length; i++) {
        const currentStudent = i;
        const curentMark = marks[i];
        if (isPass(curentMark)) {
            result.push(currentStudent);
        }
    }
    return result
};

const studentsWhoPass = findStudentsWhoPass(allStudents);
console.log(studentsWhoPass);
mserykh commented 3 years ago

Hey @dev-experience, thank you a lot for your support and explanations you provided to me to solve this one! More then appreciated.

dev-experience commented 3 years ago

@mserykh looks great! Clean and readable 👍