Jump to content

Recommended Posts

 

int = integer

when there is a call from the Javascript script using window.getElementById("square")

and in the XHTML element id there is the attribute using both char and an int as in:  <td id="square14">

 

question: does the call from the Javascript script to the XHTML element id attribute value, ignore the int that is inside of the quotation marks where the char "square" is.

 

from previous study`s i have been led to believe that an int is no longer an int when placed inside of quotation marks, yet how does Javascript deal with this ?.

I would assume Javascript is built from C object orientated and i have not been introduced to C object orientated by my own volition , yet.

Or the back end of Javascript.

 

Question was Javascript built to ignore everything but a char in a char value wrapped in quotation marks, by way of reading the ASI values of each character set that is inside of the quotation marks.

Or is the " i " a reserved character. 

The javascript script that i am working with works, and here it is along with a snip of XHTML element id .

<tr>
		<td id="square4"> </td>
		<td id="square9"> </td>
		<td id="square13"> </td>
		<td id="square18"> </td>
		<td id="square23"> </td>		
	</tr>
	</table>

 

and then the Javascript script, i whipped this out here in a hurry, could be missing something? only an example.

 

window.onload = initAll;
function initAll() {
for (var i=0; i<24; i++) {
var newNum = Math.floor(Math.random() * 75) + 1;
document.getElemntById("square" + i).innerHTML = newNum
}
}

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/210663-int-and-char-inside-of-quotation-marks/
Share on other sites

no it will not ignore the number, an integer inside of quotations isn't lost it is infact retained, what happens is that instead of a numerical data being held within it is stored as a string, it is a number with a different DataType

 

as with many other languages out there, JavaScript allows what is called DataTyping in which you can change the datatype of a value whenever you want..

 

for example..

// setting the datatype
var num = Number("45"); // will return 45 (integer value)
var num = String(num); // will turn num back to a string 

// examples of why datatyping is important 
var num = 45; // this will be an integer value by default..
var num = num + 1; // will equal 46
var num = num + '%'; // will be changed into a STRING value containing "45%"

//now look at it this way..

var num = "45"; // sets it to a STRING value of "45" not the integer value of 45
var num = 45 + num; //will result in 4545 instead of 90 which you would have been expecting..
// the reason it results in 4545 is because + for math works differently for strings, 
// since you can't add a string to a number, you can add the number INTO the string just fine
// and so it does, but many other languages will give you a case of the ass for this..

 

and you get errors for trying to divide :)..

 

answer in a nutshell: The value isn't lost, you just can't access the integer value easily.. if you took for example..

 

var name = "square45";

 

to get the number you'd need to do something like this..

 

var name = "square45";
var numb = Number(name.replace('square',''));

 

answers your Q? :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.