/Unit-Converter

🧮 The digital unit converter is built using HTML, CSS & JavaScript, it's a simple tool to help user to get the Length/ Volume/ Mass Units.

Primary LanguageHTML

Unit-Converter

The unit converter is my fourth project of Scrimba Front-End course, in this course I build web designs from scratch and structure the code to finish the layout design.

PRs Welcome Join the chat at https://gitter.im/Front-End-Checklist/Front-End-Design-Checklist CC0

Table of Contents


The Unit Converter is my fourth static website, I practice to build the function() and use "Template String" to make code easily to read.

I start the Scrimba Module 3 course- Making websites interactive and learn how to use basic HTML, CSS & JavaScript knowledge. At the end of the course, I follow the Figma template to finish the digital unit converter to quickly transfer the unit, take a look at the → Unit Converter.

How I start the project?

  • Ensure all points are taken into consideration from Figma Template. → Figma Template from Scrimba
  • Generate all conversions when the user click "Convert".
  • Round the numbers down to 3 decimal places.
  • Use the "Template String/Template literals" concept in the project to show the conversion result.

1. - Design requirements

Designing a unit converter website requires following some rules and taking into consideration that the project is not only a graphic project but a web project too. The next sections are crucial for any web project.

1.1 - Onclick

  • onclick Call a function when a button is clicked:.

    ℹ️ [onclick] GET to know more about the definition. → W3School

  • Be familiar with the HTML Tag.
  • Before working on each website project, I can build every template with my own structure concept. Building the structure before everything else will facilitate my work afterward.
<button onclick="myFunction()">Click me</button>

⬆ back to top

1.2 - Template-String

Why do we use template string. The main purpose is easy to read→ Explanation

  • Template String is a string interpolation with embedded expressions
  • Below it is an example to show how to use it.
for (let i = 0; i < myLeads.length; i++) {
     // listItems += "<li><a target='_blank' href='" + myLeads[i] + "'>" + myLeads[i] + "</a></li>"
        listItems += `
            <li>
                <a target='_blank' href='${myLeads[i]}'>
                    ${myLeads[i]}
                </a>
            </li>

⬆ back to top

1.3 - AddEventListener

Another method to active the button.

The addEventListener() method attaches an event handler to the specified element. Example shows below.

document.getElementById("myBtn").addEventListener("click", displayDate);

Resources: * 📖 addEventListener()

⬆ back to top

1.4 - Double-Click

  • When double click the function will be actived.
const deleteBtn = document.getElementById("delete-btn")
deleteBtn.addEventListener("dblclick", function() {
    localStorage.clear()
    myLeads = []
    render(myLeads)
})

Author

Shiuan Dai

⬆ back to top