Skip to main content

Command Palette

Search for a command to run...

Urgent 2k for JavaScript Developers

Solve this challenge and win 2k

Updated
β€’2 min read
Urgent 2k for JavaScript Developers
A
Software engineer and developer educator with over four years of experience building production-grade digital products for platforms serving millions of developers globally. Software engineer at Hashnode & Bug0

Hello thereπŸ‘‹, you're welcome.

If you're a JavaScript developer and you can receive naira, a friend of mine Isaac Adeshewa Faith , has asked me to give you #1, 500, and I'll add another #500 to make it #2, 000.

But! In giveaways, there is always a but πŸ˜‚, you must complete the JavaScript challenge in the story below.

β›΅ The Story

2, 000 students are expected to submit their assignment using a Google Form, but only 1, 858 responses were received from the Google Form.

βš’ The Task

As a JavaScript developer, you are required to write a JavaScript program that will do the following:

  1. Fetch out all the students who did not submit their assignments,
  2. Display the total number of students who turned in their assignments, and
  3. Show the total number of students who did not turn in their assignments.

Email of all students: Click here to view

Email of all students who turned in their assignment: Click here to view

πŸ“š Submission

Share your solution in the comment section with a brief account of your thought/coding process; your code variables and summary must be clear to a 5-year-old child who is unfamiliar with coding (I mean my friend).

Create a Github gist here for your code and share the link along with your summary.

πŸ† The Reward

#2, 000 will be sent to you via bank transfer or Nigeria recharge card.

😒 I can't participate

If you are not in Nigeria or not able to participate, you can also engage in the challenge by upvoting the solution you feel is the best.

PS: you can submit your solution, and if picked as the winner, you can nominate anyone from Nigeria to receive the prize πŸ’ƒ.

PSS: If you wish to add to the prize for the winner of this challenge, kindly send a dm on LinkedIn, join us to reward developers.

⏳ Deadline

The Winner will be announced with the solution in the next 24 hours, the deadline will be extended for another 24 hours if no winner is found.


Looking forward to what you will come up with.


I will also like to connect with you, let's connect on:

V

Summary

I enjoyed solving this problem. My process goes as follow:

  1. I created a function `getData() - function in javascript are code that performs a particular task when called.
  2. i declared a variable didnt_submit and assigned it to an empty array - variable in javascript are like a container that holds different type of information, while array in javascript are ordered list or collection of data
  3. The getData() function then fetches the data of all students and students who submitted from the google sheet which i have converted to .txt format
  4. The data gotten are now been stored in an array using the split() method - the split() method in javascript takes a string/strings and return a new array of that string/strings
  5. Now that we have converted our data - all_students and student who submitted - into an array, lets fish out students who did not submit. i achieved this using the forEach() method in javascript - forEach() method loops through an array and executes a call back function once for each element in the array. Call back function are function that are passed into another function and are only executed after another function has finished executing. In this case, everytime the loop goes through the array of all the students, it checks if the email string returned from each loop is included in the array of students who submitted, if its not, it then pushes the string into the empty array didnt_submit that was declared earlier on

Screenshot 2021-10-17 at 14-35-14 script js.png

F

solution2.jpg

This function picks an email from an array of students who submitted assignments and checks for a match in the array containing all students' emails while traversing. Once found, it deletes the email from the array (all students email array). At the end of the loop, the emails of students who did not submit will remain and the function returns an array containing their emails, the number of students who submitted, and the number of students who didn't. 😁😁😁 Not the best of solutions but it was fun giving it a try.

2
A

Well-done,

Please can you submit your code solution on GitHub gist, along with the file to test with?

Then share the URL here

F

Ayodele Samuel Adebayo , Thank you, sir,

Here's the link below πŸ‘‡πŸ‘‡. I saved the test emails in an array for easy access.

https://gist.github.com/Omar-Faruk-tech/cbbdabe04947e4ce892af886b94e07b4

2
F

This is really an interesting challenge, it did take some thinking. so here's my answer.

const studentsData = async function () {
  const allStudent = await fetch("all-student.txt").then((res) => res.text());
  const studentsSubmitted = await fetch("students-submitted.txt").then((res) =>
    res.text()
  );

  const allStudentArr = allStudent.split("\n");
  const studentsSubmittedArr = studentsSubmitted.split("\n");

  const studentsNotSubmitted = allStudentArr.filter(
    (students) => !studentsSubmittedArr.includes(students)
  );

  console.log(allStudentArr, "all students");
  console.log(studentsSubmittedArr, "students that submitted");
  console.log(studentsNotSubmitted, "students who didn't submit");

  console.log(
    `Students who turned in there assignments are ${studentsSubmittedArr.length}, while ${studentsNotSubmitted.length} students didn't submit`
  );
  console.log(
    `Total number of students are ${
      studentsSubmittedArr.length + studentsNotSubmitted.length
    }`
  );
};

studentsData();

Here's how I went about it

First I converted the google sheet files to text (txt) files so that they can be readable in a JavaScript file.

Both file names are:

all-student.txt
students-submitted.txt

Then I declared an asynchronous function called studentsData, which is responsible for handling all data fetching and doing all calculations.

Since both, all students data and does students that submitted are given I used the snippets shown below to get the text files as strings into my script file.

  const allStudent = await fetch("all-student.txt").then((res) => res.text());
  const studentsSubmitted = await fetch("students-submitted.txt").then((res) =>
    res.text()
  );

Note the use of res.text(), this is because it's a text file the script is reading.

If you should log allStudent and studentsSubmitted variables to the console, the data shown will be similar to the below picture:

Screenshot from 2021-10-14 23-10-20.png

The above image is in a string type which isn't needed, so I converted it to an array for both allStudent and studentsSubmitted variables making use of the split("\n") method.

"\n" denotes new line also read about the split method here

 const allStudentArr = allStudent.split("\n");
 const studentsSubmittedArr = studentsSubmitted.split("\n");

Now for the final step, I filter through the array of allStudentArr (all students email) checking if students that submitted their assignment are in the all students array.

If the above statement is true, then return the remaining students for the all students array.

By doing this I got all the answers for the task.

const studentsNotSubmitted = allStudentArr.filter(
    (students) => !studentsSubmittedArr.includes(students)
  );

Screenshot from 2021-10-14 23-34-50.png

Behind the scene I did Google some things, like

  • making use of the split method (I knew there was a way to convert strings to an array, but I couldn't remember)
  • writing an async function that reads text files (initially I just used the fetch method separately which wouldn't have worked)

That's it, I enjoyed working on the challenge.

10
A

This looks nice πŸ™Œ,

Please can you submit your code solution on GitHub gist, along with the file to test with?

Then share the URL here.

Kudos for the well detailed guide

1
E

image.png

image.png

The function receives both emails as string inputs. It checks emails in the general emails string that are not contained in the emails of those that submitted the assignment by utilizing the filter function. The emails are also converted to small letters in case there is a mix of cases.

It is expected that the file is downloaded in CSV (character-separated values) and the strings copied as inputs to the function.

25
A

can you create a Github gist and share the link?

1
E

Here's the link to the Github gist.

File handling was not included for better clarity to a 5-year old.

https://gist.github.com/emmiiorji/d6426bd2456f8d330cd481ca83167a0f

4

Design and Code Challenge

Part 1 of 14

This series is to document web designs and JavaScript challenge from the unclebigbay and friend's community.

Up next

Team Todo List Functionality - Challenge 12

Work with a team to build a functional todo list

More from this blog

U

Unclebigbay's πŸš€ Blog

101 posts

Software Engineer | Open-Source Contributor | Developer Educator