JavaScript - Beginner Student Help
var suitArray = ["Hearts","Diamonds","Clubs","Spades"]; var faceArray = ["Ace", - Pastebin.com
Doing a school assignment and Im totally stumped, google isnt any help nor is any of these textbooks. I need to tally up the playerhands and dealer hands and display the winner. I can get it to display the value of the current card. eg 7 of diamonds = 7 points but I cannot get it to tally up all the cards dealt. Similar TutorialsI'm doing a correspondence course on javascript, but the terminology is giving me up-hill and after hour of battling, my Javascript was just a mess. could someone help me with the javascript function. My instruction reads: "Create a web page with 5 text boxes. Assign to each text box's value attribute a value of zero. Add to each of the text boxes an onchange event handler that calls a function named calcAvg() and passes to the function the value of that text box by referencing it's document object, form name, and name and value attributes. Within the calcAvg() function, pass the five parameters to another function, named performCalc(), and assign the returned value to a variable named calcResult, then place the returned value in to another text box with a name averageResult. In the performCalc() function, calculate the average of the five numbers (by adding the five numbers and then dividing the total by 5), then return the result to the calcAvg() function. When you preform the calculation, use the parseInt() function to insure that the passes values are calculated as numbers." Please assist be as kind as to assist me with this project so I can use it as reference to the following projects that follow on the foundation of this one... My code so far; Code: <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Calculate average</title> <script type="text/javascript"> /*<![CDATA[*/ /*]]<*/ </script> </head> <body> <h1>Calculating averages</h1> <table> <tr> <td> <tr> <td>Value 1<br/></td> <td> <input type="text" name="valueOne" size="6" value="0" onchange="calcAvg()" /></td> </tr> <tr> <td>Value 2<br/></td> <td> <input type="text" name="valueTwo" size="6" value="0" onchange="calcAvg()" /></td> </tr> <tr> <td>Value 3<br/></td> <td> <input type="text" name="valueThree" size="6" value="0" onchange="calcAvg()"/></td> </tr> <tr> <td>Value 4<br/></td> <td> <input type="text" name="valuefour" size="6" value="0" onchange="calcAvg()"/></td> </tr> <tr> <td>Value 5</td><br/> <td> <input type="text" name="valueFive" size="6" value="0" onchange="calcAvg()"/></td> </tr> </td> </tr> </table> <form action="" name="averageResult" > <p>The average of the 5 numbers: <input type="text" name="cost" size="5" value="0" style="border-style: none; border-color:inherit; border-width:medium; background-color: Transparent" text="0"/></p> </form> </body> </html> i wold like to get this working. when a user enters 4 grades into the text boxes. it would give them the Avg Grade and also what Mark they got, and if they failed one out put the module they most Repeat and if they passed all out put a smiley face.. This is what i have so far.. Code: function compute() { var c = document.getElementById("c").value; var computer = document.getElementById("computer").value; var web = document.getElementById("web").value; var math = document.getElementById("math").value; document.getElementById("cost").value = totalCost = (c * 100 + computer * 100 + web * 100 + math * 100 ) /4; if(cost >=93) alert(" You got an A+") else if((cost >=85)&(grade <93)) alert(" You got an A") else if((cost >=78)&(grade <85)) alert(" You got an B") else if((cost >=60)&(grade <78)) alert(" You got an C") else if((cost >=40)&(grade <60)) alert(" You got an D") else if(cost <40) alert(" You Failed this Module") </script> </head> <body> <form method="get" action="" onsubmit='return formValidator()' > <fieldset id="personalInfo"> <h3> Student Results </h3> <!-- A bordered table for item orders --> <table border = "border"> <!-- First, the column headings --> <tr> <th> Module Name </th> <th> Pass Mark </th> <th> Final Mark </th> </tr> <!-- Now, the table data entries --> <tr> <th> C++ </th> <td> 40 % </td> <td> <input type = "text" id = "c" size ="10" /> </td> </tr> <tr> <th> Computer Systems </th> <td> 40 % </td> <td> <input type = "text" id = "computer" size = "10" /> </td> </tr> <tr> <th> Web Development </th> <td> 40 % </td> <td> <input type = "text" id = "web" size = "10" /></td> </tr> <tr> <th> Maths </th> <td> 40 % </td> <td> <input type = "text" id = "math" size ="10" /> </td> </tr> </table> <!-- Button for precomputation of the total cost --> <p> <input type = "button" value = "Total Grade" onclick = "compute();" /> <input type = "text" size = "5" id = "cost" onfocus = "this.blur();" /> </p> </fieldset> </p> <input type='submit' value='Check Form' /> </form> </body> </html> HI there.. Can you please give me code in JavaScript to create a student request form for book request from issue section of college Library.. Please help with code... Thanx in advance... Regards, I have a javascript program I'm trying to write for an introductory javascript class. The book is absolutely terrible and I've found I have a very weak grasp of how javascript functions work but I have an exam coming up and I'm getting desperate for help so I'm posting here hoping someone can help me get my head wrapped around this thing. The code is a simplified game of 21. It should randomly generate two cards for the dealer and two for the player, then display the total to the player and allow them to choose whether or not to take another card. It then decides who won. I'm including the script below: Code: <script type="text/javascript"> /*Declare Variables*/ var dealer = 0; var player = 0; var dealerPoints = 0; var playerPoints = 0; var rNum = 0; var rPlayer1 = 0; var rPlayer2 = 0; var rDealer1 = 0; var rDealer2 = 0; var hitMe = " "; function playGame() { while((playerPoints < 200) && (dealerPoints < 200)) { /*Generate 2 random numbers between 2 and 11 for the player*/ rPlayer1 = Math.floor((Math.random() * 10 + 2)) rPlayer2 = Math.floor((Math.random() * 10 + 2)) rDealer1 = Math.floor((Math.random() * 10 + 2)) rDealer2 = Math.floor((Math.random() * 10 + 2)) /* Find Players Total*/ player = (rPlayer1 + rPlayer2); /* Find Dealers Total*/ dealer = (rDealer1 + rDealer2); /*Display player total*/ while ((player <= 21) && (dealer <= 21)) { hitme = prompt("You drew a " + rPlayer1 + " card and a " + rPlayer2 + " card for a total of " + player + ". Do you want another card?"); if (hitMe == "yes") { rPlayer1 = Math.floor((Math.random() * 10 + 2)); player = (player + rPlayer1); alert("You drew a " + rPlayer1 + " card for a total of " + player + "."); } if ((player <= 21) && (dealer > 21)) { playerPoints = (playerPoints + player); alert("Player Wins Hand"); } if ((dealer <= 21) && (player > 21)) { dealerPoints = (dealerPoints + dealer); alert("Dealer Wins Hand"); } if ((dealer > 21) && (player > 21)) alert("Tie, no points awarded"); } if ((dealer <= 21) && (player <= 21)) { if (dealer > player) { dealerPoints = (dealerPoints + dealer); alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". Dealer wins this hand."); } else if (player > dealer) { playerPoints = (playerPoints + player); alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". Player wins this hand!"); } else { alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". No one wins this hand."); } if (playerPoints >= 200) { alert("Player wins game!"); } else if (dealerPoints >= 200) { alert("Dealer wins game!"); } } } } </script> hello! i have a problem: i want to change the height of my side bar as long as the text in the center of page long, it means when I have for ex 3 news in a page the side bar which have a background color must be increase to fit the long of text(3 news). i think it will do by javascript but i'm not sure! i my question isn't clear please tell me to explane more i really need it, I will start off by saying yes this is homework but I only want help. I'm trying to make the content show up in the read only boxes but I can't figure out where I'm going wrong. My test page can be found at http://sidewalk-cafe.com/test/maddox-hw2a.html. It's small. Any help would be appreciated. Code: function orderForm() { var formDaysStaying = document.getElementById("daysStaying").value; var formSeason = document.getElementById("season").value; var formPropertyType = document.getElementById("propertyType").value; document.getElementById("FEE").value = "$" + today.toFixed(2); document.getElementById("totalCost").value = "$" + today.toFixed(2); document.getElementById("today").value = "$" + today.toFixed(2); document.getElementById("due").value = "$" + due.toFixed(2); } function formTotalCost(form) { const FEE = 55; var totalCost = (formPropertyType * formSeason) * formDaysStaying; var today = totalCost * .10; var due = (totalCost + FEE) - today; if (document.getElementById("daysStaying").value == "" || isNaN(document.getElementById("daysStaying").value)) alert("Please provide the number of days you will be staying."); // Submit the order to the server form.submit(); } Hi there, im wondering if you can help me i need help in finding javascript resources to build my skills and knowledge of Jscript because im a beginner. Please help I am very new to JavaScript and I am currently following the Eloquent JavaScript book online. On one of the exercises, we are told to make a function that returns the range of the inputs in an array. I tried this code below but it doesn't seem to work. The problem seems to be in the "If" function because if I change the condition to (start < end) it seems to work. Can someone please explain to me why this is? function range (start, end) { var j = []; if (start > end) { for (i = start; i <= end; i++) { j.push(i); } } else { for (i = start; i >= end; i--) { j.push(i); } } return j; } console.log(range(10, 2)); console.log(range(2, 10)); Reply With Quote 01-26-2015, 08:49 PM #2 Labrar View Profile View Forum Posts New Coder Join Date Jun 2008 Posts 65 Thanks 0 Thanked 12 Times in 12 Posts Why you do not use something like this var range = function(start, end, step) { var range = []; var typeofStart = typeof start; var typeofEnd = typeof end; if (step === 0) { throw TypeError("Step cannot be zero."); } if (typeofStart == "undefined" || typeofEnd == "undefined") { throw TypeError("Must pass start and end arguments."); } else if (typeofStart != typeofEnd) { throw TypeError("Start and end arguments must be of same type."); } typeof step == "undefined" && (step = 1); if (end < start) { step = -step; } if (typeofStart == "number") { while (step > 0 ? end >= start : end <= start) { range.push(start); start += step; } } else if (typeofStart == "string") { if (start.length != 1 || end.length != 1) { throw TypeError("Only strings with one character are supported."); } start = start.charCodeAt(0); end = end.charCodeAt(0); while (step > 0 ? end >= start : end <= start) { range.push(String.fromCharCode(start)); start += step; } } else { throw TypeError("Only string and number types are supported"); } return range; } Thats pretty similar to php range Reply With Quote 01-26-2015, 09:25 PM #3 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts Ignore Labrar's ridiculously complicated answer to a very simple problem. Instead look CAREFULLY at this code: Code: if (start > end) { for (i = start; i <= end; i++) { Let's use your first example, where you call range(10, 2) So start is 10. And end is 2. So you get to if ( start > end ) and JavaScript executes that as if ( 10 > 2 ) Indeed, 10 *IS* greater than 2, yes? SO you the go execute the NEXT line: for (i = start; i <= end; i++) Which, of course, JavaScript then executes as for (i = 10; i <= 2; i++) But then 10 is *IMMEDIATELY* <= 2. So the for loop NEVER RUNS. All you need to do to fix your code is change Code: if (start > end) { into Code: if (start < end) { PRESTO! ********** The tiniest bit of debugging using your JavaScript debugger would have found this. But also just learning to THINK like the computer would help. Actually run the code in your head, using your example numbers, and you'd see where you went wrong. Hey guys, I am working on building a new site and was wondering if I could get some clarity on something with JS, as I am el noobo. I have the basic layout he http://www.temp3.hangnailproductions.com/ Now this is just a mock up and I plan to validate the code, make it more semantic and clean up my CSS quite a bit, but right now I just want to get an idea of what I have to do and something has caught my eye. When the page loads, it takes quite a few seconds for the javascript I have attached to populate a few areas on the screen. At the top of the page there is a random testimonial and the current date. Both are populated from this script: http://www.temp3.hangnailproductions.com/js/master.js I don't know if these areas take a few seconds because my code is horribly wrong, too large, or if this is just normal. Does the array that holds the testimonials hold too much information? I would really appreciate some help. Also, the section that says "This should be a small blurb about the link above." is going to be a snippet of text that changes when a user mouseovers a main link at the top. I think this will also be JS and included in the same "master.js" file - thoughts? Thanks very much. (And I know it is ironic that I am asking for help on a site that sells web design, but Javascript is not something I plan to push, and if need be I would hire someone to help with any in-depth JS. I thought this would just be a simple little project...) I'm trying to get this simple (not to me) ascii animation going and firebug is giving me an error saying "document.getElementById("frameArea") is null. I've got an element named frameArea and I wonder if it's buried too deep. I don't really understand this code which I admit is a big part of my problem. I have seen what it is supposed to do, which is play a simple animation. Will someone please help me decipher what this code is saying? Code: <html> <head> <title>Animation</title> <script type="text/javaScript"> function playAnimation() { frameStr = document.getElementById("frameArea").value; if(frameStr.indexOf("\r\n") != -1) { frameSeq = frameStr.split("=====\r\n"); } else { frameSeq = frameStr.split("=====\n"); } currentFrame = 0; showNextFrame(); } function showNextFrame() { document.getElementById("displayArea").value = frameSeq[currentFrame]; currentFrame = (currentFrame+1)% frameSeq.length; timer = setTimeout("showNextFrame();", 250); } </script> </head> <body> <div style="text-align:left"> <h1>My Animation</h1> <hr /> <form name="animationForm"> <table> <tr><td align="center"><b>Enter frames below separated by "====="</b> <td> <td align="center"> <tr><td><textarea name="frameArea" rows=12 cols=35 wrap="virtual"></textarea> </td> <td align="center"> <br /> <input type="button" value="Play --->" onclick="playAnimation()"> </td> <td><textarea name="displayArea" rows=12 cols=35 wrap="virtual"></textarea> </td> </tr> </table> </form> </div> </body> </html> is this code right its supposed to be a code that prompts the user for a number less than 100 and outputs only odd numbers less than or equal to the number entered by the user.for example if a user eneters the number 10 you should display 1,3,5,7,9 to the browser window?...im not sure if i have done it right..i gave it a go though! var input = prompt("Enter a number less than 100:", "10"); if( input <= 100){ nbsp; for (var i = 1, i <= input, i++2){ nbsp; document.write(i", "); nbsp; } }else{ nbsp; alert(input + " is not less than 100!"); } Hey guys, Thanks for taking the time to read my post. I am not new to programming or scripting, but I am completely new to javascript and web-based code. Hopefully you guys could help me understand what is going on and maybe help me figure out what I am trying to do. What I am trying to do: -There is an element that has a value <td class="flashField" onmouseover="clearAnswer()"> <div id="flashAnswer" onmouseover="clearAnswer()">answer string here</div> </td> -There is a text box that needs to have the answer above given to it <td class="flashField"> <input type="text" tabindex="1" onkeypress="clearAnswer()" name="q" maxlength="256" size="50"> </td> -There is a next button that needs to be executed <td align="right"> <input type="image" tabindex="2" alt="Next" src="http://website.com/images/next.gif"> </td> So what I am trying to do is create a script through Greasemonkey that will automatically do these things. I am starting small and trying to just get the value of flashAnswer to appear as an alert on the screen by using this code: var answer = document.getElementById('flashAnswer'); alert(answer); But the problem is it posts some weird value ([object XrayWrapper [object HTMLDivElement]]) that most definitely is not "answer string here" and is a bit above me at this point. Any ideas? Any help would be great guys! Thanks! -ellosiph 3 questions. I am very very new to JS (i am a html/css wiz but am just now learning js. I have taken 2 university CS courses but both were with C++)... My friend sent me these problems and wanted some help. Anyone here wanna give em a go? Given the string "Frank delete from users Beans" in a textfield If you find any sql token you find (like delete, drop, truncate, etc), strip it out, and regenerate the original string without those tokens; place the regenerated string (without the sql) back in the textfield. If You cannot strip out the sql and place the sanitized value back in the textfield, you will not get full credit for this question. Write a document that contains 5 paragraphs, and 4 headers. Create a script that finds all of them and puts "FOUND IT" beside it. Create a document that lets user's enter a planet's (like Jupiter, Saturn, Mars...) name (via a select or input field), and at the click of a button (or when the selected option was chosen), have the distance (from the Sun or Earth) appear next to that select box or textfield (which ever you choose to implement for the input from the user.) Please use Google to find the distances. HINT: use innerHTML = '...' Thanks guys! Hi all, this is my first attempt at JavaScript code. I'm trying to write code for an Adobe Acrobat form. Here is my situation: I have several boxes, all containing numbers such as 2014, 08, and 000000000. I want to concatenate them all into one long number like 080000000002014. I've looked at a ton of sample code, but nothing I try seems to work. Any help is greatly appreciated.
Hey guys, I've come here looking for a little help. Probably for a very easy problem to you guys lol. I have a script (this is just a snippet of it): Code: $("#wgo_onlineusers_list").find(":contains('Username')").closest("li").addClass("isOMM"); It basically finds the Username value using the online user list and adds them to a separate special "currently online" list at a different spot on the homepage of the forum. My problem is that if I have a simple username, for example "Big", it adds all usernames with "Big" in it. I know all I need to do is change it so that it catches only the exact username, but I'm having trouble finding a selector (if there is one) that can do this or if it'll be a little more work to fix. Is there any simple fix that is right in front of my eyes for this or do I need to rewrite the function completely? I'm sort of just getting into JS/jQuery and this forum looks like it will be incredibly helpful for me in the future cus of it's activity. Reply With Quote 01-30-2015, 05:17 AM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts You really need to ask this in the jQuery forum. But I'm with you: I don't see anything in the jQuery docs that supports "equals" instead of "contains" for text values. Hi people I'm hoping someone can help me. I have NO knowledge of Javascript but I'm not afraid of code and happy to look at it and work out what is doing what. I need someone to provide me with a small sample of code to get me started on this task. I need a webpage with a number of drop down menus. Depending on what the user selects in these menus, depends on what sentence or paragraph is then displayed in a box. For example you might have a page dedicated to food. So the user would select egg in the first drop down and the box will change to display "you can't make much with that on it's own".# You'll then select flower in the second and it'll adjust to a paragraph maybe explaining where you could go next with that. In my page I need 6 drop down menus with about 8 choices in each menu (nothing related to food). Not sure if I would need to tie this in with a database or if I could just make do with the code on the page. As I said I'm hoping someone can just kick me off with something do I can get a rough idea of how I would go about coding it. Maybe an example contain 3 drop down menus with 2 choices on each and a few possible sentences or paragraphs that it could generate in a box. If not then any advice would be really appreciated as I said I'm a complete newbie and I've never even looked at Javascript code to my knowledge. Many thanks Hi there! Here's my problems: The problem 1 is about making triangle with "*", but i must not use <center> so the triangle must be on the left side.. Here's my code: var x = parseInt(prompt("Your value","")); var A= ""; var B=[" "]; for (i=0; i<x; i++) B[i+1]=B[i]+" "; for (i=0; i<x; i++) { A = A+"*"; document.write("<br>" + B[x-i] + A) } How can i make this code more basic? The problem 2 is about taking random different elements from Array. Here's code: var items = Array(0,1,2,3,4,5,6,7,8,9), a; document.write("Secilen elemanlar: "); for (i=0; i<5; i++) { a= Math.floor(Math.random()*items.length); document.write(items[a]); items.splice(a,1); } In that problem how can i do the same thing without splice. And the problem 3 is about number triangle like this 1 232 34543 I couldn't write any code,and cane you give some advices like "what methods i must use"? Reply With Quote 02-04-2015, 07:34 PM #2 felgall View Profile View Forum Posts Visit Homepage Master Coder Join Date Sep 2005 Location Sydney, Australia Posts 6,745 Thanks 0 Thanked 666 Times in 655 Posts splice is about the only command there that you should consider using. Yuo are misusing parseInt() where you should be using Number() and the prompt() and document.write() should never be used at all - they became obsolete many years ago. Hi every one I'm a beginner to java so I have a home work assignment and I'm suppose to create a soda machine thing. What I'm trying to do is make the price of soda * quantity of soda which will equal to the price with tax but I cant figure it out @_@. I know what I'm doing wrong with the "Total" button and the "value" and "quantity" and I've been looking over the internet and playing with it like crazy. So if anyone can help me figure this out that would be great. The code and a pic is on the bottom i hope i gave you guys enough info. This is what im trying to do. |