TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Displaying Alternative Positive and Negative Numbers in JavaScript
Gaurav Jain
Jun 25
2015
Code
1.6
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<!DOCTYPE html>
<html>
<body>
<p id=
"displayseries"
></p>
<input type =
"text"
id =
"UserInput"
/>
<button type=
"button"
onClick=
"MakeSeries()"
> Enter number upto which series has to be made.</button>
<script>
function MakeSeries(){
var x = document.getElementById(
"UserInput"
).value;
var text =
""
;
var i;var j = -2;
for
(i = 1; i < x; i++) {
text +=
"+"
+ i + "
<br>";
i = i+1;
while
(j > -x) {
text += j + "
<br>";
j = j-2;
break
;
}}
document.getElementById(
"displayseries"
).innerHTML = text;
}
</script>
</body>
</html>
Alternate positive and negative number series