Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,853 members, 7,810,281 topics. Date: Saturday, 27 April 2024 at 05:09 AM

Help A Beginner Code This Using Javascript - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help A Beginner Code This Using Javascript (717 Views)

Who Knows How To Create This Using React Js...urgently Needed / How To Code This Logic With Php... / Programmers In The House, Kindly Help Me Table Like This....using Java Awt (2) (3) (4)

(1) (Reply) (Go Down)

Help A Beginner Code This Using Javascript by Fisayo22: 5:02pm On Jun 06, 2020
write a piece of code using javascript that solves second degree equations. You pass the a, b, c parameters of: ax2 + bx + c, and the solve function will compute delta = b2 - 4a*c. Test the sign of delta, and if it's equal to zero, then display (in the console, or better, in the page) the roots of the equation.

1 Like 1 Share

Re: Help A Beginner Code This Using Javascript by Tim1212(m): 6:01pm On Jun 06, 2020
Fisayo22:
write a piece of code using javascript that solves second degree equations. You pass the a, b, c parameters of: ax2 + bx + c, and the solve function will compute delta = b2 - 4a*c. Test the sign of delta, and if it's equal to zero, then display (in the console, or better, in the page) the roots of the equation.

This is absolutely easy. Drop your email
Re: Help A Beginner Code This Using Javascript by Fisayo22: 6:55pm On Jun 06, 2020
idades489@gmail.com
Re: Help A Beginner Code This Using Javascript by SUPREMOTM: 8:39pm On Jun 06, 2020
Fisayo22:
write a piece of code using javascript that solves second degree equations. You pass the a, b, c parameters of: ax2 + bx + c, and the solve function will compute delta = b2 - 4a*c. Test the sign of delta, and if it's equal to zero, then display (in the console, or better, in the page) the roots of the equation.

COPY AND PASTE it in your code editor, then link the javascript file to your HTML file so you can make use of the browser to view the operations. Ask for clarifications wherever you are confused.

let input = prompt("Enter the coefficients of X squared, the coefficients of X and the CONSTANT respectively, separated by commas, and click OK"wink,

coefficients = input.split(","wink,

a = coefficients[0],

b = coefficients[1],

c = coefficients[2];

alert(`Please Confirm if the information below is correct.\n\nCoefficient of X squared = ${a}\nCoefficient of X = ${b}\nThe constant term = ${c}\n\nNB: If any of the inputs is incorrect, please click OK and refresh your browser to input the correct values`);


let delta = Math.pow(b,2)-(4*a*c),

root1 = (-b - Math.sqrt(delta))/2*a,

root2 = (-b + Math.sqrt(delta))/2*a;

alert("delta = "+ delta);

if(delta >= 0){
alert(`Since delta is a positive number, the roots of the quadratic equation are ${root1.toFixed(2)} and ${root2.toFixed(2)}`);
}
else{
alert("The quadratic equation has complex roots"wink;
}

Re: Help A Beginner Code This Using Javascript by kay9(m): 1:01am On Jun 10, 2020
SUPREMOTM:


COPY AND PASTE it in your code editor, then link the javascript file to your HTML file so you can make use of the browser to view the operations. Ask for clarifications wherever you are confused.

let input = prompt("Enter the coefficients of X squared, the coefficients of X and the CONSTANT respectively, separated by commas, and click OK"wink,

coefficients = input.split(","wink,

a = coefficients[0],

b = coefficients[1],

c = coefficients[2];

alert(`Please Confirm if the information below is correct.\n\nCoefficient of X squared = ${a}\nCoefficient of X = ${b}\nThe constant term = ${c}\n\nNB: If any of the inputs is incorrect, please click OK and refresh your browser to input the correct values`);


let delta = Math.pow(b,2)-(4*a*c),

root1 = (-b - Math.sqrt(delta))/2*a,

root2 = (-b + Math.sqrt(delta))/2*a;

alert("delta = "+ delta);

if(delta >= 0){
alert(`Since delta is a positive number, the roots of the quadratic equation are ${root1.toFixed(2)} and ${root2.toFixed(2)}`);
}
else{
alert("The quadratic equation has complex roots"wink;
}

Nice.

I would have given different prompts for each of the 3 coefficients though... As in:

//Prompt user to input values of a, b, and c...

let a = Number(prompt("Please enter the value of a..." ));
let b = Number(prompt("Please enter the value of b..." ));
let c = Number(prompt("Please enter the value of c..." ));

Etc...
Simpler and eliminates need for the second alert (i.e. the "Please confirm..." bit).

Still, neat coding.
Re: Help A Beginner Code This Using Javascript by SUPREMOTM: 2:13am On Jun 10, 2020
kay9:


Nice.

I would have given different prompts for each of the 3 coefficients though... As in:


Simpler and eliminates need for the second alert (i.e. the "Please confirm..." bit).

Still, neat coding.

Okay
Re: Help A Beginner Code This Using Javascript by PrinceDekunle: 9:07am On Jun 10, 2020
Have you considered learning C# which is a top and highly demanded technology of the Microsoft .Net framework?

Subscribe to this channel and learn everything for free from the scratch till you become a pro.
https://www.youtube.com/channel/UCwNrlP_X_VV4vg00P2QmDnw

You can as well join our Facebook community where we answer questions, discuss and share ideas about technologies
https://www./738709033333419/?ref=share

(1) (Reply)

What Mobile APP Have You Built That Can Be Found On Play Store/apple Store / Developers Review Is Needed / Is Java Good For A Novice To Learn? And Also What Brain Work Is Required?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.