DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 970,177 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Basic terms and JavaScript syntax
hannaA
hannaA

Posted on

Basic terms and JavaScript syntax

Request a user’s name and display the response β€œHello, [name]”

let name = prompt ("enter name");
alert("hello" + " " + name);
alert('hello ${name}')

Enter fullscreen mode Exit fullscreen mode

Request a user’s year of birth, count his age, and display the result. Store the current year as a constant

let ageInput = prompt ("enter birth year");
const YEAR = 2022
alert (YEAR - parseFloat(ageInput) -1)

Enter fullscreen mode Exit fullscreen mode

Request a length of a side of a square from a user and display the perimeter of the square

let squereSide = prompt ("enter squere side length");
alert(squereSide * 4)

Enter fullscreen mode Exit fullscreen mode

Request a radius of a circle and display the area of such a circle

const PI = 3.14159;
let radius = prompt("circle radius");
alert(PI * (radius*2))

Enter fullscreen mode Exit fullscreen mode

Request a distance in km between the two cities from a user, and the time they want to cover it within. Count the speed needed to be on time

let distanceCovered = prompt("distance? (km)");
let timeBetween = prompt("time? (hrs)");
alert (distanceCovered/timeBetween)
Enter fullscreen mode Exit fullscreen mode

Create a currency converter. A user types in USD and the program converts them to EUR. The exchange rate should be stored as a constant

const RATE = 0.9;
let USD = prompt("USD exchange into EUR");
alert(USD * 0.9)

Enter fullscreen mode Exit fullscreen mode

The user types in a sum of bank deposits for 2 months with a yearly interest rate of 5%. The program counts the sum of interest

const RATE = 0.05;
let sum = prompt("input sum of your bank deposits");
alert(sum * RATE / 6)

Enter fullscreen mode Exit fullscreen mode

Oldest comments (1)

Collapse
 
samuelrivaldo profile image
Samuelrivaldo

Thanks πŸ™

This post blew up on DEV in 2020:

js visualized

πŸš€βš™οΈ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! πŸ₯³

Happy coding!