Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 4 months ago

Mortgage Calculator using Js, SCSS and HTML

sass/scss
Eduardo Pereira•120
@EduFlp
A solution to the Mortgage repayment calculator challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

This time, I'm not so proud of this project because it took me a long time to finish it. I believe the best part was learnning how to use SCSS, but it is undeniable that the project has wierd errors. In addition, I need to improve in the organization of time and execution of the next project.

What challenges did you encounter, and how did you overcome them?

The main problem was using SCSS because I didn't know what it was hot to use it. I had to watch a video on YouTube to understand this whole process.

What specific areas of your project would you like help with?

I would like to have help with SCSS and JavaScript, as I believe I did something wrong during the creation of these codes.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Bernardo Poggioni•7,030
    @R3ygoski
    Posted 4 months ago

    Olá Eduardo, parabéns pela conclusão do desafio, ele ficou muito bom.

    Sobre suas dúvidas, vou começar pelo SCSS, ele está correto em grande parte, só que tem um pequeno problema relacionado a manutenibilidade do código que seria essa parte de colocar as @media dentro dos seletores, recomendo separar seus .scss em diversos arquivos, tendo um próprio para responsivo.

    Tanto que uma dica mais pessoal minha, eu gosto de criar uma pasta scss e lá colocar um global.scss e nele importar todos outros .scss, algo assim:

    @use './abstract/var.scss';
    @use './components/input.scss';
    

    Pois isso ajuda muito na organização e separação dos SCSS assim não ficando um único arquivo gigante e cheio de informação.

    Sobre o JS, ele tem um erro, quando clicamos no botão ele reinicia a página, isso ocorre porque você usou a query no botão, mas você tinha que ter selecionado o <form>, ou seja, na parte de cálculo você pode colocar esse trecho:

    document.querySelector("form").addEventListener("submit", (event) => {//Restante do código
    

    Isso já fará com que a página não recarregue, mas mesmo assim a parte de resultado não será alterada, devido a você ter vários elementos fazendo com que a parte de resultados não apareça. São elas:

    #fullResultBox {
      display: none;
    }
    .fullResultBox {
      display: none;
      /*Restante do CSS*/
    }
    
    document.getElementById("fullResultBox").style.display = "none";
    

    Esses três trechos são redundantes, todos eles fazem isso:

    • style.display faz com que a secção não apareça, usando CSS-Inline
    • #fullResultBox faz com que a secção não apareça, usando id que tem menos prioridade que CSS Inline.
    • .fullResultBox faz com que a secção não apareça, usando classe que tem menos prioridade que id e CSS Inline.

    Então eu sugiro que você crie uma classe apenas, chamada hidden e utilize nela o display: none; daí quando você quiser esconder um trecho só usar um classList que assim você adiciona e remove a classe, exemplo:

    const fullResultbox = document.getElementById("fullResultBox");
    
    fullResultbox.classList.remove("hidden"); //Para Remover
    fullResultbox.classList.add("hidden"); //Para Adicionar
    fullResultbox.classList.toggle("hidden"); //Para Remover caso exista ou Adicionar caso não exista
    

    Outra dica, evite de repetir diversas vezes o document, por exemplo, sempre atribua o valor a uma variável, e deixe os document globais, no topo do seu JS, enquanto os específicos deixe-os dentro de funções, mas sempre atribuindo a uma variável, pois isso deixa seu código muito mais limpo e menos verboso, com fácil legibilidade.

    Outra dica quanto ao JS, opte sempre por utilizar as Template String, ao invés de concatená-las pois isso ajuda a deixar mais legível também.

    Ainda sobre o JS, você está formatando o resultado para inglês americano, só que no projeto, se utiliza a libra esterlina (£), que é o símbolo da moeda inglêsa, então o mais correto é utilizar: ('en-GB') que é o Inglês Britânico.

    Sobre o HTML, ele está muito verboso e possui muitas tags <div>, recomendo utilizar tags semânticas que assim fica mais fácil identificar alguns trechos, como por exemplo:

    • div.title poderia ser alterada pra uma <h2>.
    • div.calculation e div.result poderiam ser alteradas para uma <section>.
    • div.errorField poderia ser alterada para uma <span>.

    Também evitar o uso de camelCase para nome de classes pois isso deixa a leitura mais difícil, usar um kebab-case ou snake_case (não recomendo usar com BEM) ficam mais confortáveis, já que ajuda na legibilidade.

    E uma sugestão meio off-topic, sobre os commit, opte por dar nomes mais descritivos ao invés de alfa, beta e por aí vai. Três exemplos:

    • "feat: add calculator functionality"
    • "chore: initial setup"
    • "fix: fixes Result not showing correctly"

    Você pode encontrar sobre essa convenção aqui: Conventional Commits

    E é isso! Novamente parabéns pela conclusão do projeto, continue praticando e se aprimorando, caso tenha ficado qualquer dúvida, por favor comente abaixo que tentarei ajudar da melhor forma possível.

    Marked as helpful

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub