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

178
Visualizações
The IF give just the first condition

I make an script very easy

if the cell is 6 print "gros"

if the cell is 5 print "moyen"

if the cell is other print "faible"

But , the script write everytime "gros" (the first condition). And i don't know why

function calculdunpoids(){

  var app = SpreadsheetApp
  var feuille = app.getActiveSpreadsheet().getActiveSheet() // Je prend la feuille active du classeur actif
  var cellule = feuille.getRange(3,3) // je prend la cellule C3

if (cellule =6) {
  feuille.getRange(3,4).setValue("Gros");

  } else if (cellule =3 ) {
    feuille.getRange(3,4).setValue("moyen");
    } else  { 
      feuille.getRange(3,4).setValue("petit");
      }


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

0

From your showing script and your question, I believe your goal is as follows.

  • You want to check the cell "C3".
  • When the value of cell "C3" is 5, you want to put "moyen" to the cell "D3".
  • When the value of cell "C3" is 6, you want to put "Gros" to the cell "D3".
  • When the value of cell "C3" is not 5 and 6, you want to put "faible" to the cell "D3".

Modification points:

  • When you want to compare the values with the if statement, please use == and === instead of =.
  • When the value of cell "C3" is 5, you want to put "moyen" to the cell "D3". But, in your script, it seems that when the value of cell "C3" is 3, you want to put "moyen" to the cell "D3".
  • I think that feuille.getRange(3,4) can be used only one time.

When these points are reflected in your script, it becomes as follows.

Modified script:

function calculdunpoids() {
  var app = SpreadsheetApp
  var feuille = app.getActiveSpreadsheet().getActiveSheet()
  var cellule = feuille.getRange(3, 3).getValue();
  var destRange = feuille.getRange(3, 4);
  var value = "petit";
  if (cellule == 6) {
    value = "Gros";
  } else if (cellule == 5) {
    value = "moyen";
  }
  destRange.setValue(value);
}

References:

  • Equality (==)
  • Strict equality (===)
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