The Wayback Machine - https://web.archive.org/web/20241118113925/https://www.geeksforgeeks.org/create-a-trigonometry-toolbox-using-html-css-and-javascript/
Open In App

Create a Trigonometry Toolbox using HTML CSS and JavaScript

Last Updated : 24 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

This article will demonstrate how we can create a Trigonometry Toolbox using HTML, CSS, and JavaScript. Here, we have to give an angle in degrees as input in the input box and it calculates the corresponding value of the given angle. The application is user-friendly users can easily find the trigonometric values. There is validation if the user doesn’t enter any value and clicks on the calculate button then the message would appear as Please enter a valid angle.

Preview

trigno

 

Approach

  • In JavaScript, the function calulateTrigFun() is defined in which firstly the document.getElementById(‘angleInput’).value returns a string value which is converted to a numeric value using parseFloat, if the first character cannot be converted to a numeric value then it returns NaN.
  • If NaN is returned, then display the message “Please enter a valid angle”.
  • Then convert the input angle which is in degrees to radians using the formula angleInput * (Math. PI / 180).
  • Now, calculate the values of sine, cosine, and tangent by using corresponding JavaScript Math.sin(), Math.cos(), and Math.tan() methods.
  • Calculate the values of cosecant, secant, and cotangent by using the formulas 1/sine, 1/cosine, and 1/tangent respectively.
  • Display the values of trigonometric ratios of the input angle.

Example: The example calculates the values of trigonometric ratios of a given angle using HTML, CSS, and JavaScript.

HTML
<!--index.html file-->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0" />
    <title>Trigonometry Toolbox</title>
    <link rel="stylesheet" 
          href="styles.css" />
</head>

<body>
    <div class="calculator">
        <div class="calc_head">
            <h1>Trigonometry Toolbox</h1>
        </div>

        <label for="angleInput">
              Enter an angle (in degrees):
        </label>
        <input type="number" 
               id="angleInput" 
               min="0" 
               step="any" />

        <button onclick="calculateTrigFun()">
            Calculate
        </button>
        <pre id="output"></pre>
    </div>
    <script src="script.js"></script>
</body>

</html>
CSS
/* style.css file */

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.calc_head {
    text-align: center;
    color: rgb(137, 213, 93);
    margin-bottom: 50px;
}

.calculator {
    text-align: center;
    padding: 80px;
    border: 1px solid #7ac1e2;
    border-radius: 10px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
}

label {
    display: block;
    margin-bottom: 5px;
}

input {
    padding: 5px;
    margin-bottom: 10px;
}

button {
    padding: 10px 20px;
    font-weight: bold;
    border: 1px solid rgb(44, 231, 128);
}

#output {
    font-size: 1vw;
    margin-top: 50px;
    font-weight: bold;
    text-align: center;
}
JavaScript
//Script.js file

function calculateTrigFun() {
    const angleInput = parseFloat(
        document.getElementById("angleInput").value);

    // ParseFloat() returns first number of the parsed value.
    // If first character cannot convert then NaN is returned.
    if (isNaN(angleInput)) {
        document.getElementById("output").innerText =
            "Please enter a valid angle.";
        return;
    }

    // Convert angleInput(degrees into Radians)
    const angleInRadians = angleInput * (Math.PI / 180);

    // Calculate sine value
    const sine = Math.sin(angleInRadians); 

    // Calculate cosine value
    const cosine = Math.cos(angleInRadians); 

    // Calculate tangent value
    const tangent = Math.tan(angleInRadians); 

    // The toFixed(4) method is roundoff the 
    // value up to 4 decimal places
    const outputText = `Sine: ${sine.toFixed(4)}, 
    Cosine: ${cosine.toFixed(4)}, 
    Tangent: ${tangent.toFixed(4)}, 
    Cosecant: ${(1 / sine).toFixed(4)}, 
    Secant: ${(1 / cosine).toFixed(4)},
    Cotangent: ${(1 / tangent).toFixed(4)}`;

    // Dispaly the output
    document.getElementById("output").innerText = outputText;
}

Output:

im1


Similar Reads

Create a Product Review and Rating System Using HTML CSS and JavaScript
Creating a product review and rating system using HTML, CSS, and JavaScript involves several steps. In this article, we will create a Product Review and Rating System using HTML, CSS, and JavaScript. Approach:Create the HTML structure for your product review and rating system. You'll need sections for product information, user reviews, and a form f
3 min read
Create a Data Export and Import using HTML CSS and JavaScript
In this article, we are going to implement a Data Export and Import Project using HTML CSS & JavaScript. The application we are going to create will allow the user to export their data to a CSV file effortlessly and then import data back from CSV files. Whether you're managing lists or working with spreadsheets, this project will streamline you
3 min read
Create a CSS Fireflies background using HTML/CSS
In this article, we will see how to create the CSS Fireflies background using HTML & CSS, along with understanding its implementation through the illustration. The CSS fireflies effect can be created by utilizing the CSS animation and we will implement 3 animations to achieve the fireflies effect. To create randomness, we used different animati
7 min read
How to create fullscreen search bar using HTML , CSS and JavaScript ?
In this article, you will learn how to create a full-screen search Bar. Here You will be required to create two divs. One for the overlay container and the other for the overlay content container. HTML Code: The first step is to create an HTML file. Here we will create the basic structure for the search bar. Here we will also use an icon for the se
2 min read
How to Create Full Screen Overlay Navigation Bar using HTML CSS and JavaScript ?
Create a full screen Navigation Bar: In this article, you will learn how to create a full-screen navbar for your website. There are three methods to create a full screen overlay navigation bar which are listed below: From Left From top No animation- Just show You will be required to create two divs. One for the overlay container and the other for t
4 min read
How to Create a Binary Calculator using HTML, CSS and JavaScript ?
HTML or HyperText Markup Language along with CSS (Cascading Stylesheet) and JavaScript can be used to develop interactive user applications that can perform certain functionalities. Similarly, a binary calculator can be developed using HTML, CSS, and JS altogether. Binary Calculator performs arithmetic operations on binary numbers. Binary Calculato
5 min read
Create a Length Converter using HTML CSS and JavaScript
In this article, we will learn how to create a length converter using HTML, CSS, and JavaScript. The Length Converter is an intuitive web-based application that eliminates the complexities associated with manual conversions. Its user-friendly interface allows users to input a numerical value and select the units they want to convert from and to. Wi
6 min read
Create an Anagram Checker App using HTML CSS and JavaScript
In this article, we will see how to create a web application that can verify if two input words are Anagrams or not, along with understanding the basic implementation through the illustration. An Anagram refers to a word or phrase that's created by rearranging the letters of another word or phrase using each letter once, i.e. An anagram of a string
3 min read
Create a Prime Number Finder using HTML CSS and JavaScript
In this article, we will see how to create a Prime Number Finder using HTML, CSS, and JavaScript. The main objective of this project is to allow users to input a number and check if it is a prime number or not. Prime numbers are those, that can only be divided by 1 and themselves. We'll develop a basic web application that will take user input and
3 min read
Create a Drag and Drop Sortable List using HTML CSS & JavaScript
In this article, we will create a drag-and-drop sortable list using HTML, CSS, and JavaScript. This interactive feature will allow users to reorder items in a list by simply dragging and dropping them. Preview of final output: Let us have a look at how the final output will look like. Prerequisites to create Drag & DropHTMLCSSJavaScriptApproach
3 min read
Create a Graph Plotter using HTML CSS and JavaScript
In this article, we will create an interactive and user-friendly graph plotter using HTML, CSS, and JavaScript. This project allows users to enter mathematical equations and instantly see the corresponding graphs in a web browser, providing a user-friendly and interactive experience. The application will offer a seamless experience for exploring ma
3 min read
Create a Guestbook using HTML CSS and JavaScript
This article will show how to create a GuestBook using HTML, CSS, and JavaScript that allows users to add their name, mobile number, room number, and address to the guestbook. We have written a code that generates a card with multiple input boxes and a submit button to store the guest's information in the guestbook. ApproachFirst create an HTML car
3 min read
Create a Custom Checkbox using HTML CSS and JavaScript
This article will show you how to create a custom checkbox using HTML, CSS, and JavaScript that enables users to check on checkboxes along with the " Select all " feature. We have written a code that generates a card in the center of the window. The card displays a list of items along with checkboxes which allow the user to select items either rand
4 min read
Create a Quick access Pin using HTML , CSS and JavaScript
Quick Access Pins are a useful feature in web applications that allow users to save and quickly access their favorite or frequently visited websites, tools, or pages. These pins provide a convenient and efficient way to navigate a website or web application. In this post, we will create a Quick Access PIN using HTML, CSS, and JavaScript. Prerequisi
2 min read
Create an Online Art Auction using HTML, CSS and JavaScript
In this article, we'll guide you through the process of creating an online art auction website using HTML, CSS, and JavaScript. Art auctions are exciting events where collectors and enthusiasts bid on prized artworks. It will provide a foundation for displaying art listings and creating an appealing user interface. Preview of final output: Let us h
3 min read
Create A Custom Select Menu with Search Box using HTML CSS and JavaScript
This article will show you how to create a custom select menu with a search box using HTML, CSS, and JavaScript. First, we create an option list for the select box, and we can search for text in the text input box. The search result displays the matched option value. Additionally, we have added a "clear" button to remove your latest search. Approac
5 min read
Create a Pagination Component using HTML CSS and JavaScript
In this article, we are going to create a pagination component using HTML, CSS, and JavaScript. Websites may need multiple pages to display the items for easier navigation and better user experiences. If you are looking to display large amounts of data on your site, like a blog, charts, or graphs that show information about the same data set, you w
3 min read
Create a website using HTML CSS and JavaScript that stores data in Firebase
Following are some simple steps in order to connect our static Web Page with Firebase.  Step-by-Step ImplementationStep 1: Firstly, We are going to create a project on Firebase to connect our static web page. Visit the Firebase page to configure your project. Visit the website and click the On Add Project button as shown below. Step 2: Give a Name
3 min read
How to create a Blur Mask Image Website using HTML CSS and JavaScript ?
In this article, we will see how to create a website with a blur mask image using HTML, CSS, and JavaScript. Generally, we often see this kind of effect on many websites. When clicking the button, the box immediately becomes hidden, displaying the blurred content. The website is responsive and works well on every screen size. Preview ApproachCreate
4 min read
Create a Pomodoro Timer using HTML CSS and JavaScript
In this article, we will see how to design Pomodoro Timer with the help of HTML CSS, and JavaScript. The Pomodoro Technique is a time management method that involves breaking your work into focused intervals, typically 25 minutes, followed by short breaks. After completing four cycles, take a longer break. This technique aims to enhance productivit
3 min read
Create a Read More Read Less Button using HTML CSS and JavaScript
The "read more - read less" button is a commonly used feature that enhances user experience by providing a convenient way to reveal or hide content. The article covers two distinct approaches, including Display Inline and Display Block. Table of Content Using Display InlineUsing Display BlockUsing Display InlineCreate a separate HTML, CSS, and Java
4 min read
Create a Simple Interest Calculator using HTML CSS and JavaScript
Simple Interest is the term used to describe the rate at which money is borrowed or lent. Simple Interest Calculator serves as a practical tool for computing interest on loans or savings without compounding. It allows you to determine the simple interest on the principal amount, offering flexibility in calculating daily, monthly, or yearly interest
3 min read
How to create a revealing sidebar using HTML CSS and JavaScript?
A revealing sidebar is a hidden UI element that becomes visible upon user interaction, such as clicking or swiping, providing navigation links. The content of the page will rotate and the navigation bar will reveal itself when the menu button is clicked. ApproachCreate an HTML file with headings and a navigation bar, link the CSS file for styling,
3 min read
How to create a Landing page using HTML CSS and JavaScript ?
A landing page, also referred to as a lead capture page, static page, or destination page, serves a specific purpose and typically appears as a result of online advertising or search engine optimization efforts. Unlike a homepage, a landing page is stripped of distractions and focuses on capturing visitor information through a form, while reassurin
7 min read
Create a Volunteer Opportunity Finder using HTML, CSS and JavaScript
Creating a Volunteer Opportunity Finder using HTML, CSS, and JavaScript is a great way to help people discover and participate in volunteer opportunities. In this article, we will create a Volunteer Opportunity Finder. Prerequisite:HTMLCSSJavaScriptApproachThe HTML structure defines the layout of Volunteer Opportunity Finder. It includes an input f
2 min read
How to Create a Change Background on Scroll using HTML CSS and JavaScript ?
In this article, we will try to change the background color of the container once the scroll occurs. If a user scrolls down the page the background color will be changed. We will use the below approach to accomplish this task. Using the scroll event on the window objectIn this approach, we will use the scroll event on the window object and pass a c
6 min read
Create a Responsive Admin Dashboard using HTML CSS and JavaScript
In this article, we will see how to create the Responsive Admin Dashboard using HTML, CSS & JavaScript, along with understanding its implementation through the illustration. This project involves structuring the HTML layout for navigation, sidebar, and content, styling with CSS to ensure responsiveness, incorporating interactive elements using
10 min read
Create a Toggle Profile Card Details using HTML CSS and JavaScript
In this article, we will develop an interactive Toggle Profile Card Details application using HTML, CSS, and JavaScript Language. In this application, we have a Card Component with the user's details like their profile picture and Name. There is a toggle button, and when the button is clicked, the detailed information of the user will be displayed
3 min read
How to create a Color Generator using HTML CSS and JavaScript ?
In this article, we will develop a Color Generator application using HTML, CSS, and JavaScript. In this application, we have created the Multi Format color generator. Users can select Colour Types like RGB, HEX, and CMYK. Use the sliders to customize the color and Inout field in case of HEX and color picker to directly change the color with color i
6 min read
Create a Photo Filters and Effects Project using HTML CSS & JavaScript
In this article, we are going to implement a photo editor that allows users to apply various filters and effects to their images. This project will use HTML, CSS, and JavaScript to provide a user-friendly interface for adjusting brightness, contrast, grayscale, blur, sepia, and hue rotation filters. Users can also reset the filters to their default
5 min read
three90RightbarBannerImg