why i can't get alert info in js? [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
<script>
var currentNumber = 0;
while (currentNumber <= 12) {
alert(currentNumber);
currentNumber = currentNumber + 2;
}
<\script>
I want to prints out all even numbers from 0 to 12 , Why i can get nothing when run it?

It's possible that your ending <script> tag is causing the problem. The slash is pointing the wrong way. It should be </script>, not <\script>.
Try this code
<script>
var currentNumber = 0;
while (currentNumber <= 12) {
alert(currentNumber);
currentNumber = currentNumber + 2;
}
</script>

You're getting a syntax error because the <script> tag is not closed properly. It isn't <\script>, it's </script>. This same pattern applies to all tags, make sure you have the correct slash.
Maybe you can use a text editor that can highlight mistakes like this.
I am using SublimeText and you may have a try.

Related

Number prediction from 1 to 10 from javascript [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my code but when i run this code in console always giving me Congratulations.
Help me for solve this problem.
var val=Math.floor(Math.random() * 10) + 1;
console.log(val);
var Predict = Number(prompt("Prediction ?"));
for(var i=1 ; i <= 3; i++){
if(Predict<val){console.log("Up")};
if(Predict=val){console.log("Congratulations") };
if(Predict>val){console.log("Down")}
}
Equal operator assigns the right hand to the left hand and so the result is always true! To compare two values use double equals like this:
if (Predict==val){console.log("Congratulations") };

Javascript compiler exception: missing ) after for-loop control [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am getting an error "Javascript compiler exception: missing ) after for-loop control (null.null.script; line 29)" which would be the instantiation of the loop. My syntax looks correct.
a little help please...
var ciArray = [];
var i;
var check;
for (i = 0; check = false; i < ciArray.length; i++) {
if(ciValue == ciArray[i,0]){
ciArray[i,1] += timer;
check =True;
}
if(i == mciArray.length-1 && !check) {
ciArray[i+1,0] = ciValue;
ciArray[i+1,1] = timer;
}
}
You have too many arguments for your for loop - looks more like a while loop with a check clause right now.
inside of condition the loop for you have (i = 0; check = false; <--- in this options it your error.

Following a tutorial, cant figure out my javascript syntax mistake [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to change all instances of the word "cão" on a page to read "gato" (following an older tutorial).
All instances of "cão" are inside a span and I´m trying to change them by using getElementsByTagName method.
Since there more than one, I cant use innerHTML to change the content so I´m using a for loop to cycle through all positions but I´m getting a sytax error after the increment i++. Why is that?
var elementoHeading = document.getElementById('heading');
elementoHeading.innerHTML = "Tudo sobre gatos";
var nomesTags = document.getElementsByTagName("span");
for (var i = 0, i < nomesTags.length, i++) {
nomesTags[i].innerHTML = "gato";
}
Use semicolons, not commas, in the for construct:
for (var i = 0; i < nomesTags.length; i++) {
^ ^
The reason the syntax error is after the increment is because the JS engine expects 3 statements inside of the for's brackets, but you only gave one (commas don't terminate the statement).

javascript for loop does not work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm creating a site and i needed to do some js. I'm not that good with it but tought i would figer it out. Not. I created a for loop but it does not run.
function order(user,product){
var index;
for(var i = 0; i<users.lenght; i++){
if(user == users[i]){
index = i;
break;
}
}
var budget = budgets[index];
alert(budget);
}
the creation of the users and budgets arrays are done with php and after checking with alert() it was how it should be.
Can anyone help me please?
lenght is spelt length. The misspelt property does not exist, so it undefined, which is equivalent to 0.

JavaScript match() function does not give output [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
In JavaScript code I use regular expression match() function to find pattern and show the result, but it does not give a proper answer, means finding [i] character in giving sentences
<button onclick = "searchPattern()">pattern</button><br>
<p id = "demo"></p>
<script>
function searchPattern(){
var str = "Visti W3Schools!";
var paat = /[i]/g;
var result = str.match(patt);
document.getElementById("demo").innerHTML = result;
}
</script>
Read your JavaScript console
Uncaught ReferenceError: patt is not defined
You changed your variable name from paat to patt half way through your code.

Categories