wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if index = 44:
if index == 44:
Use == for comparison.
Python
items[99]
if (items.indices.contains(99)) items[99]
Check index.
Kotlin
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
my @arr = (60,17,24);
my @arr = (60,17,24);
Correct.
Perl
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
var x = 97;
var x = 97;
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
id: output status: hello,
id: output status: hello
Remove comma.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
b > 66 & a < 4
b > 66 and a < 4
Use 'and' not '&'.
Python
WHERE name = '68'
WHERE name = 68
Don't quote integer.
SQL
h1 {{ font-size:98px color:red; }}
h1 {{ font-size:98px; color:red; }}
Add semicolon.
CSS
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
if ($foo = 31)
if ($foo == 31)
Use ==.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
<br></br>
<br>
Self-closing.
HTML
let temp = 58; let temp = 97;
let temp = 58; temp = 97;
Duplicate declaration.
JavaScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<person age=72>
<person age="72">
Quote attribute.
XML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(63);
Correct.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
name: value age: 78
name: value age: 78
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int b = 'test';
String b = 'test';
Type mismatch.
Dart
status: test age: world,
status: test age: world
Remove comma.
YAML
<person age=82>
<person age="82">
Quote attribute.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function foo(x) print(x) end
function foo(x) print(x) end
Correct.
Lua
for i=1,21 do print(i) end
for i=1,21 do print(i) end
Correct.
Lua
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
os.sqrt(12)
import os os.sqrt(12)
Import module first.
Python
val data = 'info'
val data = "info"
Double quotes.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function compute(z:string){{return z;}} compute(79);
function compute(z:string){{return z;}} compute('hello');
Pass correct type.
TypeScript
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
println('result')
println("result")
Double quotes.
Scala
var data int = 'info'
var data string = 'info'
Type mismatch.
Go
else print('world')
else: print('world')
Colon after else.
Python
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
let data: number = 'world';
let data: string = 'world';
Fix type.
TypeScript
var x = 80;
var x = 80;
Correct.
Dart
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
assert a > 99
assert a > 99
Correct.
Python
if (result = 55) {{}}
if (result === 55) {{}}
Use === for equality.
JavaScript
items.forEach(function(item) {{ console.log(item); }})
items.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
c == '90'
c === 90
Use strict equality.
JavaScript
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{{'name':53, 'value' 68}}
{{'name':53, 'value':68}}
Colon missing.
Python
val count = 70; count = 40
var count = 70; count = 40
Use var for reassignment.
Scala
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if a = 98
if a == 98
Use ==.
Ruby
INSERT INTO orders VALUES ('output',39)
INSERT INTO orders (name, email) VALUES ('output',39);
Specify columns.
SQL
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
my @arr = (68,31,81);
my @arr = (68,31,81);
Correct.
Perl
cin >> val;
int val; cin >> val;
Declare variable.
C++
function render(): void {{ return 39; }}
function render(): number {{ return 39; }}
Return type mismatch.
TypeScript
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let list=vec![73,31,4]; let first=&list[0]; list.push(27);
let mut list=vec![73,31,4]; let first=list[0]; list.push(27);
Copy instead of reference.
Rust
let b: i32 = "output";
let b: &str = "output";
Type mismatch.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if y > 43 puts 'info'
if y > 43 puts 'info' end
Add 'end'.
Ruby
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
let s = String::from("test"); let ref=&s; s.push_str("!");
let mut s = String::from("test"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
for (int i=0; i<72; i++) {{}}
for (int i=0; i<72; i++) {{}}
Correct.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local c = 85
local c = 85
Correct.
Lua
if ($val = 66)
if ($val == 66)
Use ==.
Perl
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (count = 92)
if (count == 92)
Use ==.
C++
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{"id":"test" "age":70}}
{{"id":"test", "age":70}}
Add comma.
JSON
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
list(2)
if length(list) >= 2, list(2), end
Check length.
MATLAB
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
let mut a=82; let ref1=&mut a; let ref2=&mut a;
let mut a=82; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
let count = 78; let count = 14;
let count = 78; count = 14;
Duplicate declaration.
JavaScript
let c: Int = 'message'
let c: String = 'message'
Fix type.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM users WHRE age=34;
SELECT * FROM users WHERE age=34;
Fix WHERE.
SQL
[68, 90, 3
[68, 90, 3]
Close bracket.
Ruby