n.toLocaleString('pt-BR',{'style': 'currency', currency: 'BRL'}) //Comando pata converter uma string
'R$ 15,20'
Para comverter string para number basta usar o comando Number()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meu primeiro programa</title>
<style>
body{
background-color: rgb(44, 44, 44);
}
h1 {
color: azure;
}
</style>
</head>
<body>
<h1>Olá mundo</h1>
<script>
var n1 = Number(window.prompt("Numero 1"))
var n2 = Number(window.prompt("Numero 2"))
var s = n1 + n2
window.alert(`A soma entre ${n1} e ${n2} é ${n1 + n2}`)
</script>
</body>
</html>
Nessa aula conseguímos salvar dados dos Usuários
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
font: normal 20pt Arial;
}
</style>
</head>
<body>
<script>
var nome = window.prompt("Qual é seu nome?")
document.writeln(`Olá <em>${nome}</em>, seu nome tem ${nome.length} letras <br>`)
document.writeln(`Seu nome em maiúsculas é ${nome.toUpperCase()}`)
</script>
</body>
</html>
var n1 = 1545.5
n1.toFixed(2)
'1545.50'
n1.toFixed(2).replace('.',',')
'1545,50'
typeof n.toFixed(2)
'string'
n.toLocaleString('pt-BR',{'style': 'currency', currency: 'BRL'}) //Comando pata converter uma string
'R$ 15,20'