View Full Version : JS Basic Question
Roosterman3000
05-06-2003, 07:35 PM
I am having a huge problem right now in college. I haven't taken JS yet, next semester. My HTML teacher is asking us to make a table with the heading of Degrees, Sine, Cosine. we also have to write a script to have sine and cosine calculate (0-15-30-45-60-75-90-105-120) 0-120 in fifteen degree increments. 3 columns. and 10 rows if you count the headings. I know my html but my teacher said the way I set it up was all wrong. can someone teach me, and as I said I don't know JS yet I take it in the fall semester next year. I can't really repay anyone other than a thank you. I would appreciate, more than anything if you could send me an email at jennmike@optonline.net, either a sample copy or the actuall coding. this is my last week of class so it is due by Monday May 12th, 2003. I need the help just once , could you guys bail me out of this one thanks to you all in advanced i do appreciate your time.
scroots
05-06-2003, 07:39 PM
right, a general thing about this forum is that we will not do your homework for you, but we will help you learn how to do it.
scroots
PS. I'm sorry if i seem like i'm getting at you i'm not.
Roosterman3000
05-06-2003, 07:40 PM
I understand, and I hope I can learn in a week, is it hard?
Thank you very much I will listen to you if you can help.
scroots
05-06-2003, 07:43 PM
i will do my best to help you.
i'll post some code and links later.
scroots
Roosterman3000
05-06-2003, 07:46 PM
I am much obliged, I can't thank you enough. I have Health class in a few hours and probably will check back around 9-9:30 p.m. eastern time. Thanks again.
The Rooster
Roosterman3000
05-06-2003, 07:55 PM
the only JS that I do know is the following
<script language-"javascript")
<!-- Hide from non-javascript // browsers>
</Script>
and that is the extent of my Java.... Not much
scroots
05-06-2003, 07:55 PM
right some basic javascript code
<script type="text/javascript">
function boo(){
// stuff to do goes here.
}
</script>
that is basic javascript aplicable to most (nearly every) script.
the // means comment line
boo can be any name, or if you want to do it when the page loads miss out function boo(){ and }
the next concept is
var x =50;
sets the value of x to 50 so if you did x+5 the answer would be 55.
document.write('<P>thdjlkghkjgh</p>')
can be used to write html (make sure your html doesn't contain ' as it will mess it up.
document.write(x)
will write the value of x.
maths is sumilair to what you learn in school some advanced maths functions can be found here
http://www.javascriptkit.com/javatutors/math.shtml
so some examples
<script type="text/javascript">
function boo(){
var t =20;
var y =30;
var u =2;
var k=(t+y)/u
document.write('<P>The answer of the sum is<B>');
document.write(k)
document.write('</B>')
}
</script>
there is a way to write the last part of the code (the last three lines of the example above) in one document.write statement but it is slightly more complex.
scroots
HairyTeeth
05-06-2003, 08:44 PM
Im surprised your lecturer is asking you to do a script with no knowledge of js...anyway, aside from scroots' tutorial, here is a very big hint (http://www.codingforums.com/showthread.php?s=&threadid=19474). Have a fiddle with that and post your effort or questions.
Roosterman3000
05-06-2003, 08:51 PM
The rest of the class was sitting around staring into space wondering why and HTML class Professor would start throwing in some JS before all of us even had taken it yet. I appreciate the link. I'll give it a shot and let you know if I get it to work . Thanks
The Rooster
Roosterman3000
05-06-2003, 08:56 PM
what is the actual function I am supposed to use the teacher wants us to use both sine and cosine. No clue how to get it working. I think I can do a table now, through the link you did show, but as for the actual scripting of sine and cosine no clue . Sorry, however I do appreciate the table format. Is there a way to set up an object. the teacher mentioned that we need an object and something about Math or something to that nature.
Thanks
Rooster
HairyTeeth
05-06-2003, 09:18 PM
Thats right, you will need the Math object. You will also need to use two methods of the Math object. See scroot's link. A method for the Math object can be used like this:
//square root of a value
Math.sqrt(25)
//result 5
scroots
05-06-2003, 09:25 PM
a little example on math functions, quickly picked from the link earlier.
<script>
var x=45;
alert(Math.cos(x)) //returns cos45
x=x+15;
alert(Math.cos(x))//returns cos60 due to 45+15
</script>
if statements
if(x <= 90){
alert("x is less than or equal to 90");
//do something
}
you can also do else
if(x <= 90){
//do something
alert("x is less than or equal to 90");
}else{
alert("x is bigger than 90");
}
scroots
Roosterman3000
05-07-2003, 03:09 AM
Thanks to both of you, I think I have enough info to give it a shot. I will try to keep you posted on my outcome.
The Rooster
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.