-1

I was just making a PDFGenerator for my cross platform Phonegap app.

In the report there are fields like Patient name, Patient number, etc. So I thought it'll be a good idea to store these Patient name, Patient number, etc. in variables and change them for every different person and individual.

I don't know how to print variables in between text. Below is my statement for writing a line of text in between which a variable's text value has to be printed out:

loremipsum ='Ambulatory Blood Pressure Report\nPatient name: <heregoesthevalueofpatientname>'

Please let me know.

Andreas Lyngstad
  • 4,887
  • 2
  • 36
  • 69
C A
  • 87
  • 1
  • 8
  • `console.log`? I don't think you've tried very hard to find a solution yourself... – Bojangles Apr 05 '14 at 19:39
  • I also thought of "console.log" at first. But I don't think it's what the author wants to do. From what I understood in the question, the answer below with "+" operator seems the correct way to me. – montueron Apr 05 '14 at 20:05

1 Answers1

2

To combine literal strings with variables, you can concatenate them with the + operator.

loremipsum = 'Ambulatory Blood Pressure Report\nPatient name:' + patientname;

And just to be sure that I address the question in the title,

  • there's no built-in facility that provides the same formatting functionality as printf
  • there's no one "standard out" in JavaScript, so displaying text is different depending on how you want it to show up

(this is assuming the JavaScript is for a browser)

guest
  • 6,450
  • 30
  • 44