|
var book = {
title: "The Giver",
stars: 4
};
// draw shelf
fill(173, 117, 33);
rect(0, 120, width, 10);
// draw one book
fill(214, 255, 219);
rect(10, 20, 90, 100);
fill(0, 0, 0);
text(book.title, 15, 29, 70, 100);
for (var i = 0; i < book.stars; i++) {
image(getImage("cute/Star"), 13 + i * 20, 90, 20, 30);
}
for (var i=0; i<2; i++){
var xLivrosElias = [150];
var Autor = "Elias Araujo";
var recomendarlivro1 = true;
var recomendarlivro2 = true;
var recomendarlivro3 = false;
var count = i;
var cout = i[1];
rect(xLivrosElias[0]+150*i,20,90,100);
//Autor do tres Livros
fill(0, 0, 0);
text(Autor,15+140,29+60);
text(Autor,15+290,29+60);
text(Autor,15+1,29+60);
//Titulo do Livros
//2Livro
text("O guardião",15+290,29+30);
//3 Livro
text("O assasino do Futuro",15+140,29+10,100,30);
if(recomendarlivro1 === true){
text("O livro e bom",25,100);
}else{
text("O livro e ruim",25,100);
}
if(recomendarlivro2 === true){
text("O livro e bom",315,89);
}else{
text("O livro e ruim",315,89);
}
if(recomendarlivro3 === false){
text("O livro e ruim",165,89);
}else{
text("O livro e bom",165,89);
}
if(count ===0){
fill(196, 68, 68);
}else{
fill(156, 97, 97);
}
}
//Segunda estante de livros
fill(173,117,33);
rect(0,250,width,10);
var autor= "Alexandre";
//draw book one
//book one
fill(140,89,89);
rect(140-130,50+100,90,100);
//autor
fill(0, 0, 0);
text(autor,20,240);
//nome do livro
text("Isadora 1 O incio",20-5,240-80,90,45);
//livro 2
fill(147, 198, 230);
rect(140+20,150,90,100);
//autor
fill(0,0,0);
text(autor,20+150,240);
//nome do livro
text("Isadora 2 a procura do Rei",165,240-80,90,45);
//livro 3
fill(46,209,62);
rect(140+160,150,90,100);
//autor
fill(0,0,0);
text(Autor,20+290,240);
//nome do livro
text("Isadora 3 a consquista de
um novo Reino",305,240-80,90,40);
Richard, I still don't understand why I painted only book 3, book 2 is blank, could you say where I'm wrong to fix it
|
|
|
|
|
Look closely at the error message, it will tell you the file name, the line number and probably the column number as well. Then use your editor to go to that line - moset editors accept CTRL+G as "go to line number" - and look closely at the line it refers to. Without knowing that, it's guess work!
But my guess is this line:
document.getElementById('double_your_btc_stake').value = stake.toFixed(8); What the heck is that at the start?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Given he's posted what looks like heavily-obfuscated Javascript malware in QA as both a question with the same title as this message, and a "solution" to a question from January, I suspect he's a troll.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So do I ... but it didn't cost me anything to be polite just in case...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi guys ... I'm at the first programming experiences ... I'm trying to make a personal website to have updates of various data ... now, I would like to insert in HTML H1 the import of a value via API. .. unfortunately with what I wrote nothing works ... you can help me. Thank you
modified 1-Oct-21 7:13am.
|
|
|
|
|
First and foremost, never share the credentials on public websites. Your bearer token can be used by bots to cost you money; try to avoid that.
Secondly, I see that you have defined a function onInterval but you never call that function. You can either call that as a response to some event (button click, input, page load complete, etc.) or you can create a self-calling function.
(function onInterval() {
})(); You can see that I just wrapped the function and then called it in-place.
Lastly, you created a candleData object but you never rendered it anywhere. Maybe you can put it inside the h3 or p.u-text-palette-3-base using your container variable.
container.innerText = JSON.stringify(candleData); You should be able to see something. I have skipped the complete code because I want you to give it a try.
Learn more here:
JSON.stringify() - JavaScript | MDN
closures - What is the purpose of a self executing function in javascript? - Stack Overflow
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Quote: how to take the last given that of Close You can do that using the last index. Does this work?
const lastClose = candleData[candleData.length - 1];
Quote: I can not insert it in H2 To insert in the h2, use the query selector for h2 (right now you have of the paragraph).
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
no, nothing works .. I'm disappointed in myself
|
|
|
|
|
hello, why the number that I recover in the object is not written in H1 ??? I do not understand, I do not understand even why the number I recover in object I cannot round it with .toFixed (3) and then write it in H1
<pre><!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
const intervalTime = 10 * 1000;
const container = document.getElementsByClassName("u-text u-text-palette-3-base u-title u-text-3");
const endpoint =
"https://api.adalo.com/v0/apps/3c14481f-42d8-4944-b7a8-80ca77c16b91/collections/t_e0fz278ravbshx11g4iq7w1j0?offset=0&limit=unlikely";
function onInterval() {
fetch(endpoint, {
method: "GET",
headers: { Authorization: "Bearer cbqm69e5q48tl8v3gava0fjv6" }
})
.then((res) => res.json())
.then((data) => {
const candleData = data.records.map((a) => {
return{
close: (a.close)
};
});
const lastClose = candleData[candleData.length - 1];
console.log(lastClose);
});
}
onInterval();
window.setInterval(onInterval, intervalTime);
</script>
</head>
<body>
<h2><p class="u-text u-text-palette-3-base u-title u-text-3"></p>
</h2>
</body>
</html>
|
|
|
|
|
I'm scratching my head on this. I type in 125.00 and the decimal is cleared and becomes 12500
I see the \. which I would assume keeps the decimal point.
document.addEventListener("keydown", (e) => {
const el = e.target;
if (el.classList.contains("currency")) {
console.debug(el.id, el.value);
el.value = formatCurrency(el.value);
}
});
function formatCurrency(value) {
if (!value) return value;
return value.replace(/^[0-9]+\.[0-9]{2}/, "");
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote: value.replace(/^[0-9]+\.[0-9]{2}/, "");
Aren't you replacing those characters with a space? I avoid regex when possible but I am surprised you even get 12500 because it looks like you are replacing characters 0-9 and . with an empty space. When I run this is JSFiddle I get an empty string so I am not sure what you are doing.
|
|
|
|
|
I was thinking the same thing at first. Maybe I need to rethink this.
It's a html element textbox, so like a phone number formatter, it's a currency formatter where you type in say 125.00 or 65.47
It will reject alphabet letters.
I copied it from my phone number formatter, and used the same principals, well at least I think I did.
function formatPhoneNumber12(value) {
if (!value) return value;<br />
const phoneNumber = value.replace(/[^\d]/g, "");<br />
const phoneNumberLength = phoneNumber.length;
if (phoneNumberLength < 4) return phoneNumber;
if (phoneNumberLength < 7) {
return <code>${phoneNumber.slice(0, 3)}-${phoneNumber.slice(3)}</code>;
}
return <code>${phoneNumber.slice(0, 3)}-${phoneNumber.slice(
3,
6
)}-${phoneNumber.slice(6, 9)}</code>;
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
|
I'm back to working on this today. This works in Chrome, but not in firefox. I lose the decimal in firefox.
So in Chrome, I can type 1.23, but in Firefox it types 123
This is a filter or sort of a mask for input element of a number step .01
I thought it was the regex, and monkeyed around for about an hour with it. But it seems to have something to do with the keydown event in Firefox.
I tried this pattern
const pattern = "/^[0-9]+\\.[0-9]{2}/g";
Tried this function style
function formatCurrency(value) {
if (!value) return value;
const pattern = "/^[0-9]+\.[0-9]{2}/g";
return value.replace(pattern, "");
}
And now I'm here. It's just the dot or decimal in FireFox. Maybe it is my regex.
I thought maybe it was the textbox, so I did a console output, same thing.
Oh, I know this function looks weird, like why would I replace what I want to keep. I have no answer for that.
I am stumped... Calling it quits for today. Maybe it's a PHP issue?
document.addEventListener("keydown", (e) => {
const el = e.target;
if (el.classList.contains("currency")) {
el.value = formatCurrency(el.value);
}
});
function formatCurrency(value) {
if (!value) return value;
const pattern = '^(\d+(.\d{0,2})?|.?\d{1,2})$';
console.log('value replace=', value.replace(new RegExp(pattern)));
return value.replace(new RegExp(pattern));
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Changed the input to a textbox, and removed the step attr, and it worked on Firefox
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'm taking the w3schools tutorial on javascript. In the tutorial it is discussing numerical sort. It says since javascript doesn't sort numerals you need to use a trick of employing a comparison function with sort.
<pre><!DOCTYPE html>
<html>
<body>
<h2>JavaScript Array Sort</h2>
<p>Click the button to sort the array in ascending order.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
const points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;
function myFunction() {
points.sort(function(a, b){return a - b});
document.getElementById("demo").innerHTML = points;
}
</script>
</body>
</html>
How does function(a, b) get the input a and b? If you could give a detailed message because I'm not getting how it all works.
|
|
|
|
|
The standard sort function takes a comparison function (which "you" supply) as its argument.
As it runs, when it wants to compare two elements of the array being sorted, it calls "your" function with the elements to be compared, and uses the returned value to move the elements according to its algorithm.
The reason for doing it that way is so you can provide whatever sort order you like. for example
function(x,y){return y-x} will sort in reverse numeric order, and function(p,q){console.log(comparing p.toString() to q.toString()); return p-q} will give you a log of all the comparisons made during the sort.
If you don't specify a comparison function, it defaults to a string comparison (which is why it doesn't work with numbers).
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you very much for your response Peter_in_2780. It makes more sense, now that I know sort() is looking for a comparison function with two parameters.
|
|
|
|
|
Afternoon all. I'm putting together a kiosk style website and I'm trying to figure out how to make it recover if the connection to the server is lost. I'm using a soap service (i think...) to pass the data. Currently it just hangs up and the page has to be reloaded.
|
|
|
|
|
If it's the client network dropping off, maybe you could use the network information API to detect changes to the connection state?
Network Information API - Web APIs | MDN[^]
Beyond that, without seeing the relevant parts of the code, we can't tell you how to fix it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I am ok with all the fundamentals of javascript but i don't know what to build with it or how to even improve my profile or get a job it is really frustrating to be in this position.
|
|
|
|
|
In my opinion, just JavaScript is not enough to know to be able to do much of anything. I would suggest learning backend technologies as well, maybe some php or .Net.
|
|
|
|
|
It's quite surprising that you don't know what to build since JS may be employed not only on a client but on a server as well. Even I as .NET person had to do node.js service at my current workplace to convert doc file content to html. Unfortunately C# port wasn't mature enough.
But anyways the main usage for JS is SPA applications. Given you have any REST API of your interest you may visualize it's responses.
|
|
|
|
|
|