Skip to content

Instantly share code, notes, and snippets.

View Lakshay-Batra's full-sized avatar

Lakshay Lakshay-Batra

View GitHub Profile

Affinity Answers

Below are the answers to questions asked by Affinity Answers as first stage of interview process.

Which web tool has impressed you the most and why?

It is Chrome Developer Tools which has really impressed me as far as Web Development is concerned. Chrome DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately increases efficiency. It has a lot of things which are really fascinating. There are some really helpful and amazing features which are used frequently.

  1. View and Change the DOM: It helps you to view the website and its DOM simultaneously and we can also edit it according to the needs.
  2. View and Change the Page's Styles: It allows you to look at all the css used in a very structured manner and change it if required.
  3. View Messages and Run/Debug JavaScript in the console: We as a Web Developers often log messages to the Console to make sure that JavaScript is working as expected. Console panel in DevTools brings you the f

Date API

JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC. Date instance that represents a single moment in time in a platform-independent format.
Syntax:
There are four basic forms for the Date() constructor:

new Date()
new Date(value)
new Date(dateString)
new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]])

Array Methods

  1. toString
    The JavaScript method toString() converts an array to a string of (comma separated) array values.
var names = ["Mike", "Ross", "Tom"];
console.log(names.toString());
// Output: Mike,Ross,Tom
  1. join
    The join() method also joins all array elements into a string, in addition you can specify the separator.
function Star(el, count, callback) {
    var value = 0;
    // Write a logic to create star rating problem
    document.querySelector(el).innerHTML = `<i id="1" class="fa fa-star-o"></i>
    <i id="2" class="fa fa-star-o"></i>
    <i id="3" class="fa fa-star-o"></i>
    <i id="4" class="fa fa-star-o"></i>
    <i id="5" class="fa fa-star-o"></i>`
    var targetStars = document.querySelectorAll("i");

Conditionals

While programming there comes a point where you need to make decisions and carry out actions accordingly depending on different inputs. This can be achieved :

  • “If” statements: where if a condition is true it is used to specify execution for a block of code.
  • “Else” statements: where if the same condition is false it specifies the execution for a block of code.
  • “Else if” statements: specifies a new test if the first condition is false.
  • “Switch” statement: is another way to make decisions according to the conditions and carry out actions accordingly. It is generally used to replace else if statements when number of conditions are more.
  • “Ternary” operator: is frequently used as a shortcut for the if else statement.

If Statement

The if statement only runs if the condition enclosed in parentheses () is truthy.

Conditionals

While programming there comes a point where you need to make decisions and carry out actions accordingly depending on different inputs. This can be achieved by if...else statements, switch statement and ternary operator.

1. Basic if else

Used when you want to check just a single condition and carry out actions accordingly

var rainy = true;
if(rainy) {
  console.log("It will rain today");
} else {