Skip to content

Solution 001 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions projects/001-area-of-a-room/js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./index.js"></script>
</head>
<body>
<h1>AREA OF A ROOM</h1>
<p style="color: red;">Aggiorna la pagina web per lanciare nuovamente il programma!</p>
</body>
</html>
35 changes: 35 additions & 0 deletions projects/001-area-of-a-room/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
1. Write a program that asks the user to enter the width and length of a room.

2. Once these values have been read, your program should compute and display the area of the room.

3. The length and the width will be entered as **floating-point numbers**.

4. Include units in your prompt and output message; either feet or meters, depending on which
unit you are more comfortable working with.
*/

let width = prompt("Inserisci la largezza della stanza in m: ");
alert("Larghezza inserita= " + width)
width = parseFloat(width); // Convert the string type in a floating number type
// alert("Il tipo di dato inserito è: " + typeof width); // Check the rightness of the convertion

let length = prompt("Inserisci la lunghezza della stanza in m: ");
alert("Lunghezza inserita= " + length)
length = parseFloat(length); // Convert the string type in a floating number type
// alert("Il tipo di dato inserito è: " + typeof width); // Check the rightness of the convertion


// Added a control to be sure that the user input a positive number both integer or float
if ( width > 0 && length > 0 ) {

const area = ((width * 10) * (length* 10)) / 100; // Avoid the approssimations errors

alert("Area della stanza: " + area + "mq");

} else {

alert("ERRORE! SONO AMMESSI SOLO NUMERI >0 ! \nAggiorna la pagina web e inserisci un valore numerico quando richiesto!");

}