Click to See Complete Forum and Search --> : A few seconds of your time


Roosterman3000
05-07-2003, 11:06 AM
Hi all,

I am currently taking an HTML class and have no prior usage of JS. My professor kind of sprung a surprise on the class, he wants us to come up with the following in JS.

A table 10 Rows by 3 columns looking similar to this

Degrees Sine Cosine <--- Table Headings
0
15
30
45
60
75
90
105
120

then he wants us in increments of 15 such as you see it to convert to both sine or cosine. I tried setting it up and he told me it all needs to done through javascript. And since I have no history in this area, at least not till the fall, I kinda of need a hand. The professor mentioned something about math.object <--- no clue what it means and I am really stumped. The scripting he did show us was as follows
<HEAD>
<Script Language="Javascript">
<!-- Hide this from non-Javascript // Browsers-->
</Script>

and that is all i honestly know. If someone could set me up with a really good outline and then explain what I am doing I would greatly appreciate it.

Thanks for your time.

The Rooster

khalidali63
05-07-2003, 11:34 AM
this is what you need to do.you have the values for which you need to get sin e and cosine,
ceate a table in html exactly the way you have shown in the post.
put all of those values in an array such as

var numArr = new Array(0,15,30,45,60,75,90,105,120);

The table will have 9 rows and make sure each row has 3 cells oen that displays corresponding number from 0 to 120, give id attributes to the second and third cells such as
<tr>
<td >0</td>
<td id="sine_0"></td>
<td id="cosine_0"></td>
</tr>
and this pattern continues till the last value is eached that is 120.

What we'll do is create reference for each cell and then put sine and cosine value in it.
now in thejavascript section code like this
function setValues(){
for(var x=0;x<numArr.length;x++){
var tdSine = document.getElementById("sine_"+x);
tdSine .innerHTML = (Math.sin(numArr[x]);
var tdCosine = document.getElementById("cosine_"+x);
tdCosine.innerHTML = .innerHTML = (Math.cos(numArr[x]);
}
}


Hope this helps

Guyon
05-07-2003, 11:46 AM
When creating tables, I prefer this method...

<html>
<head>
<script language="Javascript">
function FillTable()
{
// create an array to take all the text
var aStr = new Array;

// start a table
aStr.push('<table border=1>');

// add the column headers
aStr.push('<tr><td>Degrees</td><td>Sine</td><td>Cosine</td></tr>');

// Math.sin and Math.cos use radians
var m = Math.PI / 180;

// add rows
var i;
for ( i = 0; i <= 120; i += 15 )
{
aStr.push('<tr>');
aStr.push('<td>' + i + '</td>');
aStr.push('<td>' + Math.sin(i * m) + '</td>');
aStr.push('<td>' + Math.cos(i * m) + '</td>');
aStr.push('</tr>');
}

// finish the table
aStr.push('</table>');

// get the placeholder for the table
var oDiv = document.getElementById('tablegoeshere');

// insert the new HTML
oDiv.innerHTML = aStr.join('');
}
</script>
</head>
<!-- the onload handler of the body runs the function above -->
<body onload="FillTable();">
<!-- this div is used as a placeholder. It gets filled by FillTable() -->
<div id="tablegoeshere">Watch this space!</div>
</body>
</html>

Roosterman3000
05-07-2003, 11:59 AM
Wow that is fasinating and all you did was really type one full line and bammo it filled in the rest by itself. Now I see why there is major use for javascript , you can get rid of html if you now what your doing , honestly, wow!! I appreciate the help I could ask for a better way to set it up. Just a quick question for you, so Math.sin is an object right? like i had mentioned Math.object... I am not going to say it is easy but i will say it really could be the best thing if i mastered JS. Thanks for all your help I appreciate it.

Rooster

Guyon
05-07-2003, 12:02 PM
Math.sin and Math.cos are both static functions. They kinda follow the format of Java (but don't be fooled into thinking that Javascript is related to Java).

pyro
05-07-2003, 12:04 PM
Originally posted by Roosterman3000
Now I see why there is major use for javascript , you can get rid of html if you now what your doing , honestly, wow!!javascript has it's place, but it is not replacing HTML. Think of the 10% of web users who have javascript disabled... The code above will not be doing much for them. If you are simply using it to spit out static information, you would be best to use plain HTML.

Roosterman3000
05-07-2003, 12:05 PM
How long have you been working with JS. and is there a difference between JS and Java, I thought Java was short for JS. LoL! that's why I have decided to take a course in JS to be able to know and become familiar with many of the aspects of it. I don't even know what Java is if it isn't JS.

pyro
05-07-2003, 12:08 PM
Java is not javascript. Java is programming language, that you are able to use on the internet via applets. More info can be found at http://java.sun.com

Roosterman3000
05-07-2003, 12:11 PM
Pyro, you have quite and impressive link there. A little flash to your site, 3-d movies you must be really well with a lot of programming utilities also. Nice man I sure got some of the best people to respond to me and I appreciate it thanks to all of you. This has got to be one of the best forums I have ever been on.

Thanks to All

Rooster