Sudoku Solver and American / British English Translator, why the codes have to be written in that way?

FCC, dropping students with no help at all is a terrible practice.

I have no idea how to start at all despite I had an idea how to solve both (and it should be pretty straight forward once a algo draft is made).

So i just outright look at the code to see how things worked

In the solution, American / British English Translator

this is how the clear button code is written in public/translator.js


const textArea = document.getElementById('text-input');
const translationDiv = document.getElementById('translated-sentence');
const errorDiv = document.getElementById('error-msg');

const clearBtn = document.getElementById('clear-btn');
clearBtn.addEventListener('click', () => {
  clearAll();
});

const clearAll = () => {
  return textArea.value = '', translationDiv.textContent = '', errorDiv.textContent = '';
}

it is very weird because something like

document.getElementById('clear-btn').addEventListener('click', () => {
  textArea.value = '', translationDiv.textContent = '', errorDiv.textContent = '';
  return
});

wont work as long as you delete the const and write it in one line.

why?

why you have to call const on so many parts?

and why you have to put clearAll() in the try part but not other stuff?

no idea how it started and why it is structured like this

2 Likes

another thing comes in the solution of sudoku solver

for the clear button, the solution says

const textArea = document.getElementById('text-input');
const clearBtn = document.getElementById('clear-button');
// import { puzzlesAndSolutions } from './puzzle-strings.js';

//clear button resolution
const clearInput = () => {

  const textArea = document.getElementById('text-input');
  
  return textArea.value = ''; //, setGrid('');
}

document.addEventListener('DOMContentLoaded', () => {
  // Load a simple puzzle into the text area
  textArea.value = '..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
  clearBtn.addEventListener('click', clearInput, false);
});

now one has defined const textArea = document.getElementById('text-input'); once already at the headers

why you do have to define it again within the function?

but in fact, if you remove the line of const textArea in the function, it throws an error and wont run.

and changing the const to var and deleting the line, it wont work.

why?

i am just interested if any newbies managed to complete this part. it seems googling online so far i didnt see any questions or helps online, it seems no one had completed it. i am just interested those who managed to do it themselves, what material did you read?

2 Likes

It won’t work for two reasons:

  1. Afaics the clearAll function is being tested, so if you delete it, the tests fail. That’s why it’s separated out.
  2. I’m not sure if it is linting rules or if it’s following on from that & to do with the tests, but you can’t call document directly, anything using it needs to be referenced in a variable or use window.document instead (ie referencing it explicitly rather than implicitly)

Hmm.

You keep calling the example projects ‘solutions’.

This is wrong. They are simply functional implementations of the idea - they do not demonstrate best practice.

The idea is that you look at the project and figure out how to make it. Your way.

The only requirement is to meet the user stories and pass the tests.

These projects come very late in the curriculum. If you have trouble thinking through how to implement them, I recommend going back and reviewing material from earlier in the curriculum.

To suggest that freeCodeCamp is dropping students in with no help on such a late stage project is a bit baffling to be honest. The work leading up to this point should give you lots of ideas about how to approach this.

And if you are stuck, asking for help reasoning through the ideas is going to get you a lot further than picking apart the example and complaining that it’s not the way you would do it.

2 Likes

hm. no. the shown code was from freecodecamp, and it works. even though it might not be the best optimized or readable solution, it is a feasible solution within the solution set.

everyone has different way to learn. learning coding is like learning mathematics, at majority of the levels in application or in undergrad, nobody is inventing anything new. in fact everyone is taking steps that someone did in the past. self-discovery is one way to do it, but it is inefficient, and not everyone has all the time on earth.

bills still come every month.

and then there is the part of imitation.

i am not here to pass tests but understand how things work and how it is written in a particular way.

that is not helpful either.

yes, indeed this is not the first time freecodecamp has done this.

https://old.reddit.com/r/FreeCodeCamp/comments/hqqyn0/my_react_calculator_app_for_some_reason_is/fy11o9s/

https://old.reddit.com/r/FreeCodeCamp/comments/hoji7x/warning_ahead_for_learners_fcc_advanced_node_and/

and it wasnt the first time the “past test thing” failed.

i werent even the first one to write the same thing.

and i am here asking how it worked and why there has to be convoluted way to write it. and you are one of those classic stackoverflow people who are not helpful, in the whole thread.

Then, to back up the point made here, this is just a solution to the problem. So the reason it is written that way is because it was written that way by the person who wrote it. document can’t be called directly without window preceding it in the very particular context the person who was writing it was working in, so they worked around that by assigning browser API functions that used it to a variariable. Unless you are directly copying what they wrote and adjusting it, you do not need to do things the same way. It’s good that you’re poking around. But this in particular is an example of that FCC can’t really be expected to cover everything – it is a peculiarity of the particular environment that code was written in.

please do not do that anymore. i am no longer interested in arguing over primitive ideology.

So this is a bit of a fib, isn’t it?

I apologize for insulting you, but you flat out ignored any practical explanations despite expressly stating that was what you were looking for. And you’ve ignored answers on the Reddit thread as well re improving issues with the current backend curriculum – you were pointed to GitHub issues where people are working on improving things several days ago, and you’ve rehashed things again in this thread, seemingly without checking on the progress of fixes/improvements.

Again, there is nothing wrong at all with poking around in examples and asking for clarification or suggesting improvements to the code. The FCC curriculum is huge and sprawling, so there are always places where improvements can be made.

But in this case, what you’re pointing at is an example of a quite complex program someone has built to specifications. You are being asked to build a program that conforms to the same specifications. It is there for you to build using what has been taught in FCC + your own knowledge and research. The task is not to take the example and copy it.

You are also picking out tiny pieces of code that don’t really have any bearing on the overall task – with both of the examples in this post, what you’ve highlighted is just the very specific way the author of the code wrote out one very specific piece of frontend event handling logic. The two pieces of code just do a very minor thing each, and do not have to be written that way if that logic is even included in the way it is in the example. They are not new concepts either, and they are not backend code.

Also, in Reddit you use the example of the calculator project and not being told about eval, which simplifies the solution if you do it a certain way. But it is absolutely correct to not say to learners “use eval”: eval has extremely limited usecases in JS, and its use is never encouraged; in the context of the calculator project there are much better ways to program it than using eval (they are harder and take a lot more thought and research, but no-one said it would be easy)

It’s not a game where you try to complete the tasks as fast as possible by any means: the projects are there for you to build yourself, and learn from. It is pointless just copying the existing code, or looking for shortcut solutions to get ticks on the profile as fast as possible.

1 Like

I feel similar to @lychenus here. In my opinion, out of the blue, the Quality Assurance curriculum diverged dramatically from the other curriculums. It seemed designed more to be a grind by adding in lots of tedium and intentional bugs without warning. Intentional bugs would have been welcomed if they had at least been tastefully and strategically added (as well as warned about).

Moreover, the overall quality of the lessons seems to have dropped off in this curriculum. For example, I don’t see the point in having students write an algorithm to solve sudokus puzzles in the middle of a certification about learning to write tests. It seems simply added in there to take up time, rather than to teach anything related to QA. I would have much preferred the difficulty of this project be related to the subject material (i.e., writing tests and maintaining backend functionality) rather than logic puzzles. That whole effort seems like it belongs back in the Algorithms and Data Structures program.

I don’t mean to sound like a grump but I have grown quite frustrated with this curriculum and genuinely loved and felt like I got a lot out of all of the others prior to this one. Now I feel like I’m grinding and no longer getting much use out of my time.

At this point, I would probably recommend other students do all of the other curriculums prior to this one and then skip this one, at least until it has been rethought out and/or polished a lot more.

5 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.