Math Base 2 Logarithm?
Nov 10, 2005If I have the following
2^n=a
javascript:Math.pow(2,n)=a;
and I now a how do I then find n with javascript?.
If I have the following
2^n=a
javascript:Math.pow(2,n)=a;
and I now a how do I then find n with javascript?.
the program that i want to create will first let the user input how many execution he want to perform and will determine the highest and lowest number that he inputted.
for example.
prompt: how many execution you want to perform?
i type: 5
prompt:input number:10
prompt:input number:8
prompt:input number:5
[Code]....
but it only allows for the up to inputs[6] and the code is very long. i think i can use looping in it. but i dont know to use looping in math.min and math.max.
I'm trying to get the href attribute from the base tag in the document
head. The following does not seem to work... any ideas what I'm doing
wrong?
if(!(document.getElementsByTagName) ||
!(basehrefs = document.getElementsByTagName('base')) ||
!(basehrefs.length) || !(basehrefs.length > 0) ||
!(basehrefs[0].getAttribute) ||
!(basehref = basehrefs[0].getAttribute('href')) )
basehref = ''
This is essentially a very cautious version of:
basehref = doument.getElementsByTagName('base')[0].getAttribute('href')
The big hairy if just provides checks to make sure everything can be
done and provide a contingency if it doesn't...
to append a parameter string like: '?key=val' to the currenturl and the value for the key changes based on the user input. Isthere any jquery utility that does the base url extraction fromwindow.location, so that I can append the '?key=val' to that?
View 5 Replies View RelatedI am trying to think of a good way to write some javascript that checks to see if the url entered by a user is base directory url and not an individual page. For example,
I want them to enter something like:
http://www.example.com
And not an individual page like:
http://www.example.com/index.html
I am using a generic Template in a site where different domain names may enter at different levels of a web site.By using some CSS in my <header> to set the base url.I am able to refer to the address of an image by just having.By changing the BASE URL I am able to change which image will display.So I need to obtain the URL address that the viewer, came into the web site on, and then set the BASE URL.
View 2 Replies View RelatedI need to make a drop-down menu for my multi-level website. I need all the links on this dropdown to work on every page, no matter on what level (subfolders, sub-subfolders etc.) it's called out.
i have a base href tag on every page set to my index page the links in my drop down menu look like this location='supplies/painting.htm'
where 'supplies' is the folder contained in the main root folder, so it should be working but it's not. Whenever i click on this link while i'm in the 'about_us' folder, it tries to bring out the page 'about_us/supplies/painting.htm'
Only thing left to add is that this script is included "as is" with dreamweaver, and thats why i have no idea how it works. I'd code it myself, but the client wants it that way Code:
In class based languages you can override methods in subclasses like so:
class BaseClass{
methodA(){
print( name() );
}name(){
return "--base--class--";
}}
class SubClass extends BaseClass{
name(){
return "--sub--class--";
}}
So the following code prints "--sub--class--"
(new SubClass).methodA();
So even though methodA belonged to the BaseClass, it called the overridden version found in SubClass. Would the equivalent code in Javascript print "--sub--class--" or "--base--class--" ?
I have a table there are checkbox in all rows, then I have a button in disabled.
I hope the button will be enabled if one of checkbox is checked, button should be disabled if no any checkbox is checked, what can I do?
I have an image that is encoded as a base 64 string, and I'm having trouble passing that a WCF service using $.ajax(). I initally tried using JSON to pass the argument to the web service, but I kept getting 400 Bad Request errors for anything of reasonable length (if I just pass a test string in, it makes it through, of course). I've tried calling encodeURIComponent on the string before stringifying it, but that hasn't helped. I've also tried various content types ("application/json; charset=utf-8", as well as whatever the default is) and that hasn't made a difference either. Unfortunately, the request is being made through a mobile phone, so debugging options are few. Is there an upper limit to the size of the argument that I'm passing in this? The strings can be a few hundred kb at the low end up to maybe 1 or 2 mb at the high end.
Here is a snippet of the code I am using:
$.ajax({
type: "POST",
url: "http://www.myserver.com/MyService.svc/MyFunction",
cache: false,
[Code]....
No matter what the string consists of, it errors would with a 400 Bad Request error. No further information.
Got an assignment for a javascript class and I have been banging my head against the wall for a week now.[code]In the main page I have tried several different ways to access the "src" property of the image, none of which I am 100% sure is correct. I think the problem is in the main page, in that I am not accessing the image right, but I could be wrong. I have spent hours on google and digging through the book, but I am still coming up empty handed.
View 1 Replies View RelatedIdeas on Java script Tile base game engine. You know.. with click to walk (or keyboard), inventory, grab items, talk to people, exp, levels, etc.
View 1 Replies View RelatedAnyone any idea why the Math.abs() isn't working in this code? I
thought it was supposed to convert negative numbers to whole numbers?
var se = [-27, -27, -27];
var time = 100
if(se[0] < 0){
Math.abs(se[0]); //<-- this isn't converting it to a whole number
se[0] += 1;
se[0] = (se[0]/(time / 4));
}
The result I get is -1.04 when it should be 1.12
I remember there is a programming language where you can initialize the
random number generator, so that it can - if you want - give you the exactly
same sequence of random numbers every time you initialize it with the same
parameter. Can this be done with JavaScript? I couldn't find anything in the
documentation. Basically, what I want to achieve is to obtain always the
same sequence of random numbers for the same given initialization value (but
of course different sequences for different init values).
Can this be done in JavaScript?
Javascript has a very small math function list. However there is no
reason that this list can not be extended greatly. Speed is not an
issue, unless you nest complicated calculations several levels deep. In
that case you need much more ram than a PC has to store functions
calculated in loops so that you do not have to recalculate every time
you cycle through the nest of loops. Using a HD for storage to extend
ram is much too slow for many applications.
Some functions such as hyperbolic ones are easy to add, since they are
just simple combinations of the built in javascript math functions. I
have found a few examples on the web such as Bessel functions. I found
far fewer javascript math functions than I expected on Google searches.
Thus I have had to write several functions of my own.
See http://www.cwdjr.net/math/I0L0andI1L1.html for an example of two
"functions from hell" that are very difficult to evaluate. Fortunately
there are Fortran programs that can be used as a starting point. I was
able to modify the Fortran programs to work on javascript. I have used
these functions for technical applications in the past.
The page is set up to reject the NN 4 series, because it will not
support some of the script needed such as .toExponential(n) and
to.Fixed(n)for writing output in exponential or fixed format. I was
amazed that even the old MSNTV(former WebTV) set-top box, that no
longer is being made, will even support these output formats. I wonder
about IE4. If it will not support these output formats, I can easly
block it by checking for document.getElementById.
The code works properly on the latest versions of IE6, MSN9, Firefox,
Mozilla, Netscape, and Opera. I am not selling anything, so for a
special interest page such as this, I see no need to support older
browsers.
The advantage of doing math with javascript is that it is so portable.
You can do it anywhere you can use a computer, or you can do it on your
own local computer offline. There are several math programs for PCs
that will do very much more than you can hope to do with javascript.
Unfortunately the program I would like costs about US$ 1800. Also there
are versions you can install on a server, but these also are expensive.
why I am getting Nan
<script type="text/javascript">
var num1;
var num2;
var num3;
[Code]....
<script type="text/javascript">
function countItDown(){
var current=parseFloat(document.getElementById("currentsecondscount").value);
var seconds=current;
document.getElementById("debug").innerHTML="S "+current;
var minutes=Math.floor(seconds/60);
[Code]...
im not sure why Firefox is doing this. it seems to work fine on Firefox 3.6.3 for Mac.
I have this simple manual photo slide show. It shows four photos and when you click the next button and it moves one photo over and one photo back for the previous button. I have to moving by changing the CSS property of 'left' by 195 pixels each move. So for it to move next it will subtract 195 pixels from the left property and for moving back it add 195 pixels to the left property. I have the code setup so when you click it changes the property of left to either -195 or 195 pixels but I need it so it actually does the math, not just give it a set value. But I don't know how to do that.code...
View 3 Replies View RelatedI have a website that allows users to enter complex mathematical formulas into a text field and evaluates them.
I am currently using eval() because it not only can handle all the standard mathematical functions, but also gives them access to the Math object. That way the users can use functions such as Math.max() and everything else.
I realize, though, that using eval is evil, I assume because a malicious user might throw in some more damaging javascript that would be run without checking it. (That's why eval is evil, right?)
Is there a way that I can allow my users to construct complex mathematical formulas and use the Math object (or an equivalent) without potentially opening my site up to harm?
Just started to learn java & came up with the following, but can't get the math.round to work. Anyone able to tell me where I'm going wrong please ? code...
View 9 Replies View RelatedI have 3 divs. I want distribution them random (when refresh the windows, three divs' position will be changed)
I think Math random() can solve this problem, but how to do that? code...
i have a column which have some numbers into...
and any td of this columns have class="something"...
so i want to sum the tds of that column which have the same class name when i click on the first cell..
ie
Code:
+---+
| | -> i click here
+---+
| 3 | -> class="ha"
+---+
| 4 | -> class="haha"
+---+
| 2 | -> class="ha"
+---+
| 8 | -> class="haha"
+---+
so here i want the sum in this column where the class name is "ha"...
so the sum is 3+2 = 5...
all that have to happens when i click on the first cell!
any suggestion??
Code:
function finalSize(){
var size = document.getElementById('size').value;
var margin = document.getElementById('margins').value;
var mirrors = document.getElemntById('mirrorsRadio').value;
var size_array = size.split('x');
var h = size_array[0];
var w = size_array[1];
var finalH = ''
var finalW = ''
if(margin > 1){
finalH = h * margin;
finalW = w * margin;
document.getElementById('finalSize').value = finalH+'x'+finalW;
}else{
newH = h * margin;
newF = w * margin;
finalH = newH + h;
finalW = newW + w;
document.getElementById('finalSize').value = finalH+'x'+finalW;
}
}
I see it's ok, but it gives me this error:
Object doesn't support this property or method.
I don't know what I'm doing wrong. All I know is PHP, but from what little I learned on Javascript, my brain is telling me I'm right, but my experience is telling me I'm wrong. XD
I have following codes
<html><head>
<title>this is first math exercise within Java Script</title>
<script lanuage="Javascript">
function total(){
Var amount1 = text1.value
Var amount2 = text2.value
Var total=eval(amount1) + eval(amount2)
text3.value=total
alter("Correct Answer")
} </script>
</head><body><center><form>
<table width="20%" border="1" cellpadding="1" cellspacing="1" >
<tr><td width="10%" align="center">Amount1</td>
<td width="10%"><input type="number" name="text1" value="" min="1001" max="8000"></td>
</tr><tr><td width="10%" align="center">Amount2</td>
<td width="10%"><input type="number" name="text2" value="" min="1001" max="8000"></td>
</tr><tr><td width="10%" align="center">Total</td>
<td width="10%"><input type="number" name="text3" value="" min="1001" max="8000""></td>
</tr><tr><td width="10%"></td>
<td width="10%"><INPUT TYPE="button" NAME="Submit" VALUE="Compute" onclick="total()">
<input type=reset Value="Clear" size="30"></td></tr>
</table></form></center></body></html>
I want to get summed value in text3 but function does not execute.
I'm trying to write a function that does a simple math function between some textfields.
There are 4 variables : Unit price, Discount, Quantity and Total
Unit price is a fixed variable.
Discount, Quantity and Total depend on the fixed variable and also on the values of eachother. (ie : if qty=2 then total=2xUnit Price) etc...
I want to be able to show the changing values in real time.
So if I have 3 textfields and I change qty, I want it to update Total based on the discount and the qty. If I update discount, I want to update Total based on qty and discount.
I'm guessing I would have to write three functions and call each one from their respective textfields.
How to write a function, and call it so that passes the unit price to the funtion, gets the values of all of the textfields and then changes them all to their new values?
Initiate function function count(form){Initiate vars
var answer=0;
var lower_limit;
var upper_limit;
var func;
should it not be parseInt? Maybe thats why.
parseInt(form.user_input.value)
[Code]...
As you can see by what im doing here, I'm trying to make it so that a person can enter a math expression in a form text box and based on what the user entered, javascript will compute the summation of the function.
What I'm truly asking here is, how do I make Javascript correctly compute the sum, based on what the unser inputed? Because when I enter for example, 1/x, a lower limit, and a upper limit, it just returns an answer of NaN. I'm one step away from building a Javascript function to compute the sum of any user inputed function. It's just the text parsing thats got me knocked down.