Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
javascript alert function not displaying mesaage

I was trying to take names from the user as input and tried to display the names so that the first character is capitalised and the remaining letters in lower case. PROBLEM: alert function at the last is not displaying the message. CODE: ''' var Name = prompt("Enter your name: ");

var Name = prompt("Enter your name: ");
var firstLetter = Name.Slice(0,1);
var finalFirstLetter = firstLetter.toUpperCase();
var remainingLetter = Name.Slice(0,Name.length);
var FinalRemainingLetter = remainingLetter.toLowerCase();
var captalisedName = finalFirstLetter + FinalRemainingLetter;
alert("Hello, " + CaptalisedName);

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Few notes,

  1. Javascript's slice function is lowecased.
  2. At the end, when you alert the output, your variable must be the same case as you declared

Run the snippet below, to see the desired output.

var Name = prompt("Enter your name: ");
var firstLetter = Name.slice(0,1);
var finalFirstLetter = firstLetter.toUpperCase();
var remainingLetter = Name.slice(1,Name.length);
var FinalRemainingLetter = remainingLetter.toLowerCase();
var captalisedName = finalFirstLetter + FinalRemainingLetter;
alert("Hello, " + captalisedName);

about 4 years ago · Juan Pablo Isaza Relatório

0

This is the error message your code runs:

{
  "message": "Uncaught TypeError: Name.Slice is not a function",
  "filename": "https://stacksnippets.net/js",
  "lineno": 13,
  "colno": 24
}

Make sure you check the console when you run your code to see if any errors are being thrown, it can save a lot of headaches.

The function is not capitalized, so it would look something like this:

var name = prompt("Enter your name: ");
var firstLetter = name.slice(0,1).toUpperCase();
var remainingLetter = name.slice(1, name.length).toLowerCase();
var capitalizedName = firstLetter + remainingLetter;
alert("Hello, " + capitalizedName);

I would also try to follow some sort of naming convention to reduce capitalization errors. In the example above I'm using the javascript standards, which are camelCase for variables and functions, and UpperCamelCase is reserved for data types and classes.

Wiki for naming conventions

Here is the same code with const , Have fun learning JS!

const name = prompt("Enter your name: ");
const firstLetter = name.substring(0, 1).toUpperCase();
const remainingString = name.substring(1).toLowerCase()
alert("Hello, " + firstLetter + remainingString);

about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you could replace var with const. Sometimes this also solves the error.. Like this..

const name = prompt("Enter your name: ");
const firstLetter = name.substring(0, 1).toUpperCase();
const remainingString = name.substring(1).toLowerCase()
alert("Hello, " + firstLetter + remainingString);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda