I am trying to use JavaScript to solve the linear equation with variables.
So my try is this:
var CE = parseFloat(document.getElementById("CE").value)
var CF = parseFloat(document.getElementById("CF").value)
var EF = parseFloat(document.getElementById("EF").value)
var x1=algebra.parse("CE^2+2*EF*x-EF^2");
var x2=algebra.parse("CF^2");
var eq= new Equation(x1,x2);
var h=eq.solveFor("x");
I know I should not put the valuable in "" mark, but I do not know where I should put them.
Please help me. Thank you!
You can use template String in ES-6 to simplify writing these complicated string.
var x1=algebra.parse(`${CE}^2+2*${EF}*x-${EF}^2`);
var x2=algebra.parse(`${CF}^2`);
var eq= new Equation(x1,x2);
var h=eq.solveFor("x");
Related
This code is not working:
dojo.require("com.ibm.team.workitem.shared.common.BigDecimal");
var BigDecimal= com.ibm.team.workitem.shared.common.BigDecimal;
var vlr1 = new BigDecimal('88.66');
var vlr2 = new BigDecimal('44.2844835221463');
var vlr_result = vlr1.multiply(vlr2);
When creating the vlr2 variable, nothing happens, neither an error.
What am I doing wrong?
How is the correct way to create the BigDecimal value with the number 44.2844835221463?
Thanks in advance.
Luiz Cesar.
$(function(){
var lr-lineheight = $('#sub').height();
$("#lefty,#righty").css({"line-height":lr-lineheight+'px'});
)}
So I'm not really sure what im doing wrong here, but I'm on a deadline and would like a bit of help. Please give some input.
Variables cannot be declared with a dash in them.
You can use underscores to split variables:
var my_variable = 1;
or you can use camel case:
var myVariable = 1;
Is there a better way to do this using chaining?
var url = "www.mycompany.com/sites/demo/t1"
var x = url.split('/');
console.log(x);
var y = x.pop();
console.log(y,x);
var z = x.join("/");
console.log(z);
I tried something like but wouldn't work since pop just returns the last value and not the rest:
parentUrl = self.attr('Url').split("/").pop().join("/");
You could certainly do this with a regex replacement:
var url = "www.mycompany.com/sites/demo/t1";
var z = url.replace(/\/[^\/]+$/, '');
console.log(z);
This Regex should do the trick:
var url = "www.mycompany.com/sites/demo/t1"
console.log(url.match(/^(.+)\/(.+)/));
I solved it using lodash. The _.initial() does exactly what I'm looking for.
var url = "www.mycompany.com/sites/demo/t1";
var x = _.initial(url.split("/")).join('/');
console.log(x);
The regex solutions worked as well. However, I don't know how to read regex yet so I didn't feel comfortable using something I didn't really understand. But they work so thanks.
EDIT: My project already has the lodash library so I'm not adding a library just for this :)
Can anyone tell me the use of document.frmReport in JavaScript code?
My application uses this but I don't have any information about this. Besides, it is an HTML DOM object from what I've searched on the internet. A speedy answer would be very helpful. The code is like this:
function fnAddItems(strSource,strTarget)
{
var f = document.frmReport;
var doAdd;
var objSourceCombo = eval("document.frmReport."+strSource);
var objTargetCombo = eval("document.frmReport."+strTarget);
var selSourceLen = objSourceCombo.length;
var selTargetLen = objTargetCombo.length;
var strSourceText;
var strSourceValue;
var arrIDs;
var arrIDs1;
var IsMultipleSelected;
var strFormat;
}
document.frmReport returns undefined for me. Also, there's no official documentation about it, and it's not in the specs.
So my guess is it's something that's added to the document object earlier in your application by someone else, and is being used now.
Look for document.frmReport = something (probably an object)
Do you understand why relying on eval and global variables is a bad practice now?
I have converted my .xml code to .json
For xml I am using something like this:
var stage = xml.getElementsByTagName("stage" + game.current_stage)[0];
How can you do that in json?
I want something like this:
var stage = json."stage"+ game.current_stage;
You can still use the zero index for the JSON, and the correct syntax is:
var stage = json["stage" + game.current_stage][0];
If I understand the question:
var stage = json["stage"+ game.current_stage];
var stage = json["stage" + game.current_stage];
would you like to read by using Javascript or what?
Then below code helps. Please try with that
var stage = JSON.parse(json)["stage"+ game.current_stage];