DEV Community

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

Top comments (1)

Collapse
 
samuelrivaldo profile image
Samuelrivaldo

Thanks 🙏