Homework help - Javascript coin jar -


our teacher asked create jar of coins count how many pennies, dimes, , etc have , gives total amount of money.

this template want use

https://online.pcc.edu/content/enforced/70599-22278.201302/labs/frameworks/lab4template.html?_&d2lsessionval=0zb6smzbbcq8enpn4hdqk4js0 

he want enter pennies, nickels, dimes, quarters in same text box separated comma. question is, how can that? don't know how in javascript. can lead me in right direction.

here code

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"     "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title> 122 lab 4 template </title>     <meta name="author" content="lee middleton" />     <meta name="keywords" content="cis122" />     <meta name="description" content="cis 122 lab 4" />     <link rel="stylesheet" type="text/css" href="/content/enforced/70599-22278.201302/labs/frameworks/../../new122_style.css?_&amp;d2lsessionval=femqrn1p4ynbw7srb8h38srqw" />     <style type="text/css">         .container {             border: 1px solid black;             border-radius: 15px;             width: 350px;             margin: 25px auto;             padding: 10px;         }         .result {             width: 175px;             float: left;         }         p { margin: 5px 0 0 5px;}         .clear { clear: both; }         input[type='button'] {             margin: 10px 0 0 5px;         }     </style>     <script language="javascript">         function countcoins()         {             // add code here count coins , display answers         }     </script>  <script type="text/javascript" src="/d2l/common/mathjax/2.0/mathjax.js?config=mml_htmlormml%2c%2fd2l%2flp%2fmath%2fdisplay%2fconfig.js%3fv%3d9.4.1000.156-10" ></script></head>  <body> <h1>cis 122 lab 4</h1> <div class="container"> <h2>sort-o-coin</h2> <form name="clubform" style="margin-bottom: 10px;"> <div style="margin-left: 10px;">coin jar <input name="coinjar" size="40" type="text" /></div> <p>number of pennies: <span name="pennies"></span></p> <p>number of nickels: <span name="pennies"></span></p> <p>number of dimes: <span name="pennies"></span></p> <p>number of quarters: <span name="pennies"></span></p> <p>number of half-dollars: <span name="pennies"></span></p> <p>total number of coins: <span name="totalcoins"></span></p> <p>total value: <span name="totalvalue"></span></p> <input value="count coins" onclick="countcoins()" type="button" /></form></div> </body> </html> 

your text, split comma using string.split

var valuesarray = yourinput.split(','); 

it gives array of values split ,. accessible indexes.

var first = valuesarray[0]; var second = valuesarray[1]; //and on... 

as counting, can figure out there.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -