|
Print the following pattern using for loop
*****
****
***
**
*
*
**
***
****
*****
|
|
|
|
|
You just need a loop that counts down from 5 to 1 and then up back to 5. Give it a try. If you need specific assistance with Javascript then go to JavaScript Tutorial[^].
|
|
|
|
|
I got it! Thnx
modified 29-Aug-22 21:01pm.
|
|
|
|
|
|
You have edited every question you have ever posted to read "I got it txh", after you have been given the answer.
This is not only extremely rude, it will NOT prevent your teachers from discovering your attempt to cheat on your homework.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
export class myClass implements OnInit {
counter=0;
static counter:any;
onListItemClick(PackDef: PackDefinition): void {
this.itemClicked.emit(PackDef);
this.counter++;
console.log(this.counter);
and
<pre>import { myClass } from '../../../';
dialogRef.afterClosed().subscribe((result: any) => {
this.saveMyMethod();
console.log("Final1"),
console.log(myClass.counter);
});
saveMyMethod(): void {
console.log("Final2"),
console.log(myClass.counter);
Do you know why I cant have correct counter after "Final1" or "Final2"? but I have a correct counter in myClass.
modified 26-Jul-22 12:58pm.
|
|
|
|
|
Afi_sh wrote: counter=0;
static counter:any;
Took a look at that part real closely.
Jeremy Falcon
|
|
|
|
|
Hello Everyone,
I am in a Core Technologies class and Javascript coding is a topic that I don't fully understand. For our coding assignment, we were directed to www.w3schools.com where we could try different codes, run them and see how they work. When given the original code, I understand how to change it and I see how the modification changes what is displayed but, I don't fully understand the basic elements of the code and how to start from scratch to write one. Can anyone help me out with understanding the basic elements of a code starting from scratch or could you suggest a website that can explain it from scratch? Thank you in advance for any help you can offer.
Regards,
John
|
|
|
|
|
W3Schools Online Web Tutorials[^] is probably the best site for learning web based technologies. So go to the Javascript section and follow it through, it will explain everything.
|
|
|
|
|
|
First, welcome to web development. It's an industry that only continues to grow. We'd be happy to help with specific questions.
As far as just getting started with all the concepts, nothing beats a good book. The website linked is great, but usually book authors take much more time to explain things.
I wish I could recommend a good current book, but I started web development back in the 90s. That crap is out of print by now I'm sure. But, once you do get the concepts, I can recommend a reference website. The Mozilla foundation (same peeps that make FireFox) have an online resource called the Mozilla Developer Network (MDN).
Learn web development | MDN[^]
It will literally be one of the best reference sites to use, once you get the concepts down.
Jeremy Falcon
|
|
|
|
|
Got it! Thnx
modified 29-Aug-22 21:01pm.
|
|
|
|
|
Shouldn't the comparisons look something like,
if (a == b)
{
}
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
As you suggest, the '=' should be '=='. As is
if (randomNum = 0) sets randomNum to 0 and the 'if' effectively becomes 'if (0)' which is a falsy result (not false, but treated false), so it carries on. Then
else if (randomNum = 1) sets randomNum to 1 and the 'if' effectively becomes 'if (1)' which is a truthy result (not true, buth treated as true) so it succeeds.
Many people may jump up and down and say it shows what a dreadful language JavaScript is; but the same thing is valid in many other languages, e.g. C, C#, Java.
|
|
|
|
|
Got it thnx!
modified 29-Aug-22 21:01pm.
|
|
|
|
|
You need to show the code you have for people to help you. No one here is going to write your complete assignment.
|
|
|
|
|
function colorSelector (colorCode) {
let randomNumber = Math.floor((Math.random() * 100));
if (randomNumber < 10) {
console.log("green");
}
else if (randomNumber >= 10 && randomNumber < 19) {
console.log("yellow");
}
else if (randomNumber > 19) {
console.log("blue");
}
return (randomNumber);
}
console.log(colorCode);
This is how far I got. Im confused what should be inside the function and what should we outside. Im also not sure if im using the return operator the right way.
modified 29-Aug-22 21:01pm.
|
|
|
|
|
Your code is quite confused, and confusing. You specify that the function takes an input parameter named colorCode , but you never refer to it in the function. Your if/else clauses include the variable condition which is never defined anywhere. Finally you return the randomNumber for no reason I can see.
- The function does not need an input parameter, unless you want to pass it a random number. Assuming yo do not, then generate the number as the first step.
- The if statements only need to be as follows
- 1: If the value is less than 10 set colorCode to "green"
- 2: Else If it is less than 50 set colorCode to "yellow" (we already know it is not less than 10)
- 3: Else set it to "blue" (it must be 50 or greater)
- return colorCode to the caller of the function.
modified 16-Jul-22 7:11am.
|
|
|
|
|
So, you nearly there.
function colorSelector (colorCode) {
let randomNumber = Math.floor((Math.random() * 100));
if (randomNumber < 10) {
console.log("green");
}
else if (randomNumber >= 10 && randomNumber < 19) {
console.log("yellow");
}
else if (randomNumber > 19) {
console.log("blue");
}
return (randomNumber);
}
console.log(colorSelector(50)); I got a warning that "colorCode" doesn't exist. And true, it doesn't. That makes it confusing, because there's two options. Let's forget them for a second. Try the code I gave you, vary the number. It writes to the console also.
Member 15708114 wrote: I know that I have to use the Math.floor and Math.random to create a random number and the if and return operators but I think im messing up the order. Please help anyone. You creating a random number inside the function. You want to "pass" it to the function as an argument.
So you don't see where on thing starts and the other ends? It's called "scope". Ask your teacher. Once clear, ask to step.
It executes one line, shows result in debug. That way you see how the computer "steps" through your instructions.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
else if (randomNumber >= 10 && randomNumber < 19) {
^^^^^^^^^^^^^^^^^^
We know it is >= 10 from the previous if statement.
else if (randomNumber > 19) {
And it this point it must be > 19, so all that is needed is a simple else clause.
|
|
|
|
|
Richard MacCutchan wrote: And it this point it must be > 19, so all that is needed is a simple else clause. That's the advanced course. I somehow think his teacher might have escaped that.
It's a beginner.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
But that is nothing to do with programming, it is simple mathematical logic.
|
|
|
|
|
Correct. It got to do with education.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
There was no requirement for a "random number"; the requirement was for a function that accepts a number.
And that function could be tested any number of ways; usually with a "console app" that accepts a number as input from the user and then uses that number in that function, and displaying the result.
if ( n < 10 ) {
else if ( n <= 50 ) {
} else {
}
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hello,
I am having a JSON Object as below in Node JS editor:
{"replyType":"queryDataRqst","requestId":169,"errCode" ,"options" ,"ccuSec":1657531129,"ccuNanosec":257000000,"replyData":[["IncidentStatusLine","\"machineId\":1111,\"incidentTidx\":101016,\"helpTidx\":101017,\"componentTidx\":100100,\"type\":2,\"state\":2,\"priority\":10,\"args\":{\"userData\":[{\"_d\":858993459,\"stringTidxValue\" ,\"longValue\":-634515298,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" },\"_d\":286331153,\"stringTidxValue\" ,\"longValue\" ,\"realValue\" .0,\"nullValue\" }]},\"text\":\"\",\"sequencenum\":287,\"timestamp\":1657522757472000000,\"wintimestamp\":133019963574720000,\"hashval\":-492839581,\"hideable\":false}"]]}
Now I need extract the value from the above JSON String as below:
{"userData":[{"_d":858993459,"stringTidxValue" ,"longValue":-634515298,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" },"_d":286331153,"stringTidxValue" ,"longValue" ,"realValue" .0,"nullValue" }]}
How to get this value using Node JS.
Thanks,
Uday
|
|
|
|
|