# Java Script Interview Questions

Showing Questions 1 - 20 of 41 Questions
First | Prev | Next | Last Page
Sort by:
|
•

#### JAVASCRIPT difficulty

Hi

I am currently learning javascript and I came across this exercise question:

c

var numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 14, -99];

function secondLargest(num){
return 0;

#### Anshul

• Jul 1st, 2019

```Codevar numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 92, 14, -99];

function secondLargest(num){

var first = num[0];
var second = num[0];

for(var i=1; i<num.length; i++)

if(first < num[i]){
second = first;
first = num[i];
}else{
if(second < num[i]){
second = num[i];
}
}

return second;
}

function reverse(str){

var rstr = "";

for(var i=0; i<str.length; i++){

rstr = rstr + str.charAt(str.length - i -1);

}

return rstr;

}

```

#### Oleg

• Dec 5th, 2014

Here is it.

```Codevar numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 14, -99];
function secondLargest(num){
var mn = num[0];
for(var i=1; i<num.length; i++)
if(mn < num[i])mn = num[i];
return mn;
}
function reverse(str){
var rstr = "";
for(var i=0; i<str.length; i++){
rstr = rstr + str.charAt(str.length - i -1);
}
return rstr;
}
```

•

#### Swamy Karnam

• Jul 23rd, 2015

Rejeevrm, thanks

#### RAJEEVRM

• Sep 12th, 2008

//Javscript code pagination.js file===========function Pager(tableName, itemsPerPage) {    this.tableName = tableName;    this.itemsPerPage = itemsPerPage;  &nb...

•

#### Web Page Redirect

What are the three ways of redirecting a web page logincheck.php to logged.php using1. HTML2. JavaScript3. PHP

#### arunkarnati

• Oct 1st, 2014

1. HTML: You cant redirect a page using HTML 2. JavaScript: window.location = "logged.php" OR window.location.href = "logged.php" OR location.href = "logged.php" Just so you know if you want to redir...

#### kedarPhp

• Sep 2nd, 2010

At the starting of the logincheck.php page you can add the javascript code as follow

```Code<script language='javascript'>
you can use one of the following
</script>
<?php
exit();  //write the exit to exit the current php page execution
?>```

•

#### Print the number in rverse order

How can i print the numbers in descending order without using looping structure in php/javascript

#### Satya

• Nov 15th, 2012

```Codefunction reverse(str){
return str.split("").reverse().join("");
}```

•

#### Ranjan Kumar

• Sep 22nd, 2011

```Code
function CollFunction()
{
}
```

#### salijaffar

• Feb 27th, 2009

Just write the name of the function and a pair of small brackets then semi-colon after it.example.functionName();

•

#### How to use email validation in Java script.Like User can't enter invalid email address?

bicu

• Member Since Sep-2005 | Feb 2nd, 2006

First of all, here is the javascript function that tests if an email address is valid.
It checks for a lot of things: to see if the email contains a "@" sign and a dot, checks to see if the @ is before the dot, and so on.

<script>
function isMail(str)
{
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1) return false;
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
if (str.indexOf(at,(lat+1))!=-1) return false; if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
if (str.indexOf(dot,(lat+2))==-1) return false;
if (str.indexOf(" ")!=-1) return false;
return true;
}

// the next function will be used to validate the form. I made this as a separate function because you might want to validate more fields.
function validate_form()
{
if (!isMail(document.form1.mail.value))
{
document.form1.mail.focus();
return false;
}
// if the value entered is not a valid email address,
// we show a message, focus on the field and return false.
// returning false will make sure the form is not submitted

// if we got here, it means the email address is valid
return true;
// return true means that the form is submitted.
}

</script>

After placing this function in the code, here is what you need to put in the form.

Let's say the form only has the email address and a submit button.

<form action="/" method="post" onsubmit="return validate_form()" name="form1">
<input type="text" name="email" value="">
<input type="submit" name="submit_button" value="continue">
</form>

#### Ravi Maggon

• May 16th, 2011

<html>   <head>     <script type="text/javascript">   function check()    {     var filter=/^[a-zA-Z0-...

#### SwapnilSwapnil

• Sep 7th, 2009

There are many varieties of email validation. This one is simple, but effective.function isValidEmail(str) {   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); }

•

#### Render HTML inside DIV Element

Write a one line code to render HTML inside a DIV element.

#### hari_nowayout

• Mar 25th, 2011

In case of html, this can be done by document.getElementByID("divname").innerHTML("write any html tags u want here ");in case of JQuery, it is done by \$("#divname").html("any html");

•

#### Script to check every character

Write a code to get the text box data and to check each and every char?

#### vasanth.kvj

• Nov 23rd, 2009

function numvalid(a) {  var numStr="1234567890"; var thisChar; var counter=0; for(var i=0; i < a.length; i++) { thisChar=a.substring(i,i+1); if(numStr.indexOf(thisChar...

#### princesh

• Nov 18th, 2008

Read the input textCheck the length of the string Substract the length by one And then keeping doing this till end of the string.

•

#### Javascript for Website validation

How to validate website address using javascript? User should not be allowed to enter special characters except hyphen(-).

#### anjumanohar

• Jul 17th, 2009

•

#### JavaScript and JScript?

How and in what ways does JavaScript differ from JScript?

#### imedvedeva

• Feb 26th, 2009

The biggest difference now between Javascript and JScript are all of the additional commands that JScript supports that allow access to activeX and the local computer. These commands are intended for ...

•

#### Redirecting a page

How to redirect a page using JavaScript

#### brijbhushansh

• Oct 13th, 2008

Window.location="filename"

#### chenw2000

• Aug 2nd, 2008

Use location.href = "new page URL"

Showing Questions 1 - 20 of 41 Questions
First | Prev | Next | Last Page
Sort by:
|