The logic is not quite coming together in these arguments

//Resolved

In my attempt to add the parameters together and then divide by 2 to pass the result into the sqrt method, I encountered an issue where only the last parameter of the function was being returned.

When using typeof, it indicated that the arguments were numbers, so I'm uncertain about what is causing this problem.

function calculateTriangleArea(x, y, z) {
    let area, perimeter; 

    perimeter = (x + y + z)/2;
    
    //Heron's formula
    area = Math.sqrt(perimeter * ((perimeter - x)  * (perimeter - y) * (perimeter - z)));

    return area;
}

//calculateTriangleArea(3, 3, 9) The perimeter returned 9 as the argument for c, while it should have been 7.5.


Answer №1

modify

area = Math.sqrt(perimeter * ((perimeter - a)  * (perimeter - b) * (perimeter = c)));

into

area = Math.sqrt(perimeter * ((perimeter - a)  * (perimeter - b) * (perimeter - c)));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Lodash efficiently with tree shaking

After experimenting with using lodash functions as a specific import versus as a destructured object, I noticed a significant difference in file size. When imported as shown below, the size is only 14.7KB. https://i.sstatic.net/avFcR.png However, when I t ...

Handling Removal of Selected Option in React Material-UI Autocomplete Single Selection

I am currently using material UI autocomplete to create a single-select dropdown. However, I have encountered an issue wherein the onChange event does not get triggered when I click the close button on the right side of the input. This prevents my state fr ...

Develop a RESTful API in Node.js that allows for the sending of audio files along with JSON

My current project involves a REST API that I've built using node and express. I'm now facing a challenge where I need to send both JSON Data and an Audio File in a single http request. The audio file needs to be playable on the client side. JSO ...

What is the best way to search through directories for JSON files in JavaScript?

I am looking to navigate through directories to find json files and combine them all into a single json file for each directory. I consider myself a beginner in javascript. The javascript code should be executed by calling it in the Terminal, instead o ...

Component in React/JavaScript designed for transmitting data to ASPX backend

I am in the process of updating a legacy ASP.NET application to modernize it. One specific page that I am working on is MyPage.aspx, along with its corresponding codebehind file MyPage.aspx.cs. In order to enhance the functionality of a custom user contro ...

Unlock the power of Angular pipes in window.open with URL parameters!

<div class="member-img" onclick="window.open(childEpisode.File_URL | fullPath)"> </div> The fullPath function concatenates the domain part to the relative URL stored in file_URL. However, there seems to be an issue as it i ...

What is the best way to create a transparent sticky header that blends with the background while still maintaining visibility over images and text?

On my web page, the background features a radial gradient but the content extends beyond the viewport, causing the center of the gradient to not align with the center of the screen, producing the desired effect. However, I'm facing an issue with a sti ...

Converting a curl command into an AJAX request

Here's the curl bash command that I'm currently using: curl -d "username=UID&password=PASS" http://localhost:8080 I'm looking to convert this into an ajax request in Java Script. Could you guide me on how to do that? This is what I ha ...

How to keep text always locked to the front layer in fabric.js without constantly bringing it to the front

Is it possible to achieve this functionality without using the following methods? canvas.sendBackwards(myObject) canvas.sendToBack(myObject) I am looking to upload multiple images while allowing them to be arranged forward and backward relative to each o ...

Exploring the functionality of Angular directives for bidirectional data binding with object references

In my custom Angular directive (v1.4.3), I am passing two bindings. The first binding is an Object with 2-way binding (model: '=') that can either be an Array or a single Object like [{something: 'foo'}, {something: 'moo'}, ...

JavaScript Decoder Tool

I have been experiencing issues with my encoder, as it is not functioning as I had anticipated. The variable "message" was declared through an input added to my HTML page var ENCODE_OPC = ['a', 'b', 'c', 'd', &apo ...

"Can you please provide guidance on accessing the current value of Ref in react-native

I have exhausted all options provided in this URL: How to extract values from input types using this.refs in reactjs? From ref.current.value to ref.value to ref._getText(), everything returns as undefined. After inspecting the JSON output of the ref objec ...

Issue with handlebars template

Below is a handlebars-template that I have: <script id="pins-list-template" type="text/x-handlebars-template"> {{#if ListCount > 0}} <ul> {{#each ListData}} <li> <img src="assets ...

Is it possible to both break down a function parameter and maintain a named reference to it at the same time?

When working with stateless functional components in React, it is common to destructure the props object right away. Like this: export function MyCompoment({ title, foo, bar }) { return <div> title: {title}, ...</div> } Now ...

Using AngularJS to display multiple objects in the same ng-repeat loop

Is it possible to display two objects simultaneously in ng-repeat? <tr data-ng-repeat="target in targets |session in sessions |filter:query | orderBy:orderProp"> ...

Using Vue.js within Cordova platform allows developers to create dynamic

Having trouble integrating a Vue.js app into Cordova. Everything seems to be working fine, except I'm unsure how to capture Cordova events (deviceready, pause, etc.) within my Vue application. Using the Webpack template from vue-cli. This is my file ...

Retrieving the status of a checkbox using jQuery to obtain a value of 1 or

Incorporating jQuery, I am able to retrieve the values of all input fields using the provided code snippet. However, an issue arises when dealing with checkboxes as they return "on" if checked. How can I modify this to receive a value of 1 when a checkbox ...

Troubleshooting Email Communication Errors: A Persistent Challenge

I am new to nodemailer and trying to work on a simple application. However, I keep encountering errors within the nodemailer module when running my app. Here is my app.js code: const nodemailer = require('nodemailer'); const transporter = node ...

Creating a tooltip with a left arrow and a bordered design

I am looking to create a tooltip that displays its content after clicking on the tooltip tip icon. Currently, it only works on hover, but I want it to be clickable and mobile responsive. Desktop design should resemble: https://i.sstatic.net/FQPyt.png Mob ...

Ways to change the color of a dynamically created button when it is clicked in Javascript and HTML

I'm attempting to create a button for each letter of the alphabet and then switch the color from white to black when clicked. function CreateAlphabetButtons() { var i = 0; var stop = 5; for (i = 65;i < 91;i++) { var button = docu ...