/    Sign up×
Community /Pin to ProfileBookmark

Why My Java Calculator Not Work?

here is html…

[code]

<!DOCTYPE html>
<html>
<head>
<title>My WebsiteB</title>
<link rel=”stylesheet” type=”text/css” href=”stylesB.css” />
<meta charset=”utf-8″>
<meta name=”description”
content=”” />
<meta name=”keywords”
content=”” />
<meta http-equiv=”author”
content=”” />
<meta http-equiv=”pragma”
content=”no-cache” />
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
</head>
<body>
<header>
<h1>Clock Numerology Calculator</h1>
</header>
<div class=”nav”>
<h3>Converts Words Into Numbers</h3>
<p>Enter Word(s) Or Phrase:</p>
<div class=”content”>
<input type=”text”>
<button onclick=”calculate()”>Calculate</button>
<div class=”result”></div>
</div>
</div>
[script src=”JavascriptB.js”>[/script>
<ul id=”list-one”>
<label id=”label-one”>Number Description Database</label>
<li><a href=”Tens.html”>0-99</a></li>
<li>100-199</li>
<li>200-299</li>
<li>300-399</li>
<li>400-499</li>
<li>500-599</li>
<li>600-699</li>
<li>700-799</li>
<li>800-899</li>
<li>900-999</li>
<li>1000-1999</li>
<li>2000-2999</li>
<li>3000-3999</li>
<li>4000-4999</li>
<li>5000-5999</li>
<li>6000-6999</li>
<li>7000-7999</li>
<li>8000-8999</li>
<li>9000-9999</li>
<li>10000-19999</li>
<li>20000-29999</li>
<li>30000-39999</li>
<li>40000-49999</li>
<li>50000-59999</li>
<li>60000-69999</li>
<li>70000-79999</li>
<li>80000-89999</li>
<li>90000-99999</li>
</ul>
<table id=”encryption” border=”black”>
<tr align=”center”>
<th bgcolor=”lightgrey”>2</th>
<th>A</th>
<th>Z</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>3</th>
<th>B</th>
<th>Y</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>12</th>
<th>C</th>
<th>X</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>11</th>
<th>D</th>
<th>W</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>15</th>
<th>V</th>
<th>E</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>17</th>
<th>F</th>
<th>U</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>18</th>
<th>G</th>
<th>T</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>13</th>
<th>M</th>
<th>S</th>
<th>H</th>
<th>N</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>10</th>
<th>O</th>
<th>I</th>
<th>L</th>
<th>R</th>
</tr>
<tr align=”center”>
<th bgcolor=”lightgrey”>7</th>
<th>J</th>
<th>K</th>
<th>P</th>
<th>Q</th>
</tr>
</table>
</body>
</html>

[/code]

Finally, here is Java…

[code]
var NUMEROLOGY = {
‘a’: 2, ‘b’: 3, ‘c’: 12, ‘d’: 11, ‘e’: 15, ‘f’: 17, ‘g’: 18, ‘h’: 13, ‘i’: 10, ‘j’: 7, ‘k’: 7, ‘l’: 10, ‘m’: 13, ‘n’: 13, ‘o’: 10, ‘p’: 7, ‘q’: 7, ‘r’: 10, ‘s’: 13, ‘t’: 18, ‘u’: 17, ‘v’: 15, ‘w’: 11, ‘x’: 12, ‘y’: 3, ‘z’: 2

};

var input = document.querySelector(‘input’);
var button = document.querySelector(‘button’);
var result = document.querySelector(‘.result’);

function calculate(){
result.innerHTML = ”;

printResult(NUMEROLOGY, ‘Numerology’);
}

function printResult(list, text) {
var letters = input.value.toLowerCase().replace(/[^0-9a-z])/g, ”).split(”);
var sum = 0, l, i;
for(i = 0; i < letters.length; i++){
l = letters[i];
sum += list[l] || parseInt(l);
}

result.innerHTML += ‘<div class=”result-text”>’ + text + ‘ ‘ + ‘</div>’;
}

[/code]

FYI, I got the calculator code from a Coding Website. When I run it on that site, it works. But when I run it in my browser as my own webspage, it doesn;t work.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@sibertNov 22.2022 — > @4539123#1648635 When I run it on that site, it works. But when I run it in my browser as my own webspage, it doesn;t work.

A wild guess is that the path to the javascript is wrong. And the regex may be invalid.

https://jsfiddle.net/2sxcrp3y/
Copy linkTweet thisAlerts:
@cootheadNov 22.2022 —  @4539123#1648635

[i][color=#008]"FYI, I got the calculator code from a Coding Website.

When I run it on that site, it works. But when I run it

in my browser as my own webspage, it doesn't work."[/color]
[/i]

[/quote]


If it works on a site, then post a link that site.

This will allow members to compare it with your posted

code and perhaps provide a solution for you.

[i]coothead[/i]
Copy linkTweet thisAlerts:
@4539123authorDec 16.2022 — @coothead#1648638

Thank you for allowing me to post the link. Here it is...

@coothead#1648638

https://onecompiler.com/html/3xtrr9t4t
Copy linkTweet thisAlerts:
@cootheadDec 16.2022 — Hi there 4539123,

I copied the code from that site and tested it locally without any problems.

[i]coothead[/i]
Copy linkTweet thisAlerts:
@4539123authorDec 16.2022 — @coothead#1649260

Okay, I understand copy/paste, but a few questions...

1: what is text/css? what is app.css?
&lt;link rel="stylesheet" type="text/css" href="app.css"&gt;

2: can I add "id" tags to the following divs?

&lt;div class="nav"&gt;
&lt;h3&gt;Convert Words To Numbers&lt;/h3&gt;
&lt;p&gt;Enter the name:&lt;/p&gt;
&lt;div class="content"&gt;
&lt;input type="text"&gt;
&lt;button onclick="calculate()"&gt;Calculate&lt;/button&gt;
&lt;div class="result"&gt;&lt;/div&gt;
&lt;/div&gt;
Copy linkTweet thisAlerts:
@cootheadDec 17.2022 — 1 This code...

<link rel="stylesheet" type="text/css" href="app.css">

...is incorrect.

It should be...

<link rel="stylesheet" href="app.css" media="screen">

There is no app.css file, at present.

If there was then it would be used to style the HTML.

2 You could add id attributes to the div elements, but

it begs the question, "why do you want to?"

[i]coothead[/i]
Copy linkTweet thisAlerts:
@4539123authorDec 18.2022 — @coothead#1649264

1: why would I ad id tags to div elements?

A: in case I want to style them in css. But at the point of being so frustrated at not getting this to work, I will settle for a website that has no style as long as the calculator works.

2: where should the script element start and end? I tried adding it inside the head with no success. And then just before and after the input element with no success.

3: what to name the javascript? I have a folder "WebsiteB". Inside that folder is " index.html" and "css.css". And I have the src element to look for the JavaScript file named " javascript.js" ....and still nothing works.

I have programmed a nice looking site all in css. But the java I can't get to work still.

PS: tag = identifier; element = specific html "function"? I may have the terms switched I don't know.
Copy linkTweet thisAlerts:
@cootheadDec 18.2022 — Hi there 4539123,

check out the attachment that may be found here...

[url=https://www.mediafire.com/file/q70c038g7mbeope/numerology-calculator.zip/file][b]numerology-calculator.zip file[/b][/url]

It will show you how to apply the javascript and CSS files to the HTML file.

[i]coothead[/i]
×

Success!

Help @4539123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...